diff --git a/Rest.Net/HttpListenerResponseExtensions.cs b/Rest.Net/HttpListenerResponseExtensions.cs
index 058731b..3280778 100644
--- a/Rest.Net/HttpListenerResponseExtensions.cs
+++ b/Rest.Net/HttpListenerResponseExtensions.cs
@@ -49,27 +49,6 @@ namespace MontoyaTech.Rest.Net
return response;
}
- ///
- /// Sets the response content type to text encoded as utf16 and writes the given text to it.
- ///
- ///
- ///
- /// This response.
- public static HttpListenerResponse WithText16(this HttpListenerResponse response, string text)
- {
- response.ContentType = "text/plain; charset=utf-16";
-
- var bytes = Encoding.Unicode.GetBytes(text);
-
- response.ContentLength64 = bytes.Length;
-
- response.OutputStream.Write(bytes, 0, bytes.Length);
-
- response.OutputStream.Dispose();
-
- return response;
- }
-
///
/// Sets the response content type to text and writes the given text compressed to it.
///
@@ -122,27 +101,6 @@ namespace MontoyaTech.Rest.Net
return response;
}
- ///
- /// Sets the response content type to json encoded as utf16 and serializes the object as json and writes it.
- ///
- ///
- ///
- /// This response.
- public static HttpListenerResponse WithJson16(this HttpListenerResponse response, object obj)
- {
- response.ContentType = "application/json; charset=utf-16";
-
- var bytes = Encoding.Unicode.GetBytes(JsonConvert.SerializeObject(obj));
-
- response.ContentLength64 = bytes.Length;
-
- response.OutputStream.Write(bytes, 0, bytes.Length);
-
- response.OutputStream.Dispose();
-
- return response;
- }
-
///
/// Sets the response content type to json and writes the given json compressed to it.
///
@@ -355,25 +313,6 @@ namespace MontoyaTech.Rest.Net
return response;
}
- ///
- /// Sets the response content type to html encoded in utf 16 and writes the given html to it.
- ///
- ///
- ///
- /// This response.
- public static HttpListenerResponse WithHtml16(this HttpListenerResponse response, string html)
- {
- response.ContentType = "text/html; charset=utf-16";
-
- var bytes = Encoding.Unicode.GetBytes(html);
-
- response.ContentLength64 = bytes.Length;
-
- response.OutputStream.Write(bytes, 0, bytes.Length);
-
- return response;
- }
-
///
/// Sets the response to include the given stream and sets the length and content type if possible.
///
@@ -695,7 +634,7 @@ namespace MontoyaTech.Rest.Net
if (requestComponents.Count == 0)
return false;
- var absolutePath = Path.Combine(basePath, requestComponents.Separate(Path.DirectorySeparatorChar));
+ var absolutePath = Path.Combine(basePath, requestComponents.Concat(Path.DirectorySeparatorChar));
if (File.Exists(absolutePath))
{
@@ -842,7 +781,7 @@ namespace MontoyaTech.Rest.Net
requestComponents.Add(indexFile);
//Combine the path into an absolute path
- var absolutePath = Path.Combine(basePath, requestComponents.Separate(Path.DirectorySeparatorChar));
+ var absolutePath = Path.Combine(basePath, requestComponents.Concat(Path.DirectorySeparatorChar));
//If a file exists, return true
if (File.Exists(absolutePath))
diff --git a/Rest.Net/HttpRequestMethod.cs b/Rest.Net/HttpRequestMethod.cs
index 28096ed..a9e6406 100644
--- a/Rest.Net/HttpRequestMethod.cs
+++ b/Rest.Net/HttpRequestMethod.cs
@@ -14,13 +14,21 @@ namespace MontoyaTech.Rest.Net
public enum HttpRequestMethod
{
Get,
+
Head,
+
Post,
+
Put,
+
Delete,
+
Connect,
+
Options,
+
Trace,
+
Patch
}
}
diff --git a/Rest.Net/MimeTypeExtensions.cs b/Rest.Net/MimeTypeExtensions.cs
index 7941f12..13e0396 100644
--- a/Rest.Net/MimeTypeExtensions.cs
+++ b/Rest.Net/MimeTypeExtensions.cs
@@ -8,15 +8,23 @@ namespace MontoyaTech.Rest.Net
{
internal static class MimeTypeExtensions
{
+ ///
+ /// Returns the mime type if possible for known extensions.
+ ///
+ /// The extension to get the mime type for. Example valid values: ".txt", "txt"
+ ///
public static string GetMimeType(this string extension)
{
+ //If the extension is null or empty use the default mime type.
if (string.IsNullOrWhiteSpace(extension))
return "application/octet-stream";
+ //Remove the leading . if needed
if (extension.StartsWith("."))
extension = extension.Substring(1);
- switch (extension.ToLower())
+ //Check the extension against known types.
+ switch (extension.ToLower().Trim())
{
case "323": return "text/h323";
case "3g2": return "video/3gpp2";
@@ -584,7 +592,6 @@ namespace MontoyaTech.Rest.Net
case "xwd": return "image/x-xwindowdump";
case "z": return "application/x-compress";
case "zip": return "application/x-zip-compressed";
-
default: return "application/octet-stream";
}
}
diff --git a/Rest.Net/RestClientGenerator.cs b/Rest.Net/RestClientGenerator.cs
index a4614b6..7f03574 100644
--- a/Rest.Net/RestClientGenerator.cs
+++ b/Rest.Net/RestClientGenerator.cs
@@ -162,11 +162,14 @@ namespace MontoyaTech.Rest.Net
{
foreach (var include in routeIncludes)
{
- var types = this.FindTypeDependencies(include.Type);
+ if (include.Type != null)
+ {
+ var types = this.FindTypeDependencies(include.Type);
- foreach (var type in types)
- if (!dependencies.Contains(type))
- dependencies.Add(type);
+ foreach (var type in types)
+ if (!dependencies.Contains(type))
+ dependencies.Add(type);
+ }
}
}
}
diff --git a/Rest.Net/RouteInclude.cs b/Rest.Net/RouteInclude.cs
index 2897031..0ac4b80 100644
--- a/Rest.Net/RouteInclude.cs
+++ b/Rest.Net/RouteInclude.cs
@@ -28,6 +28,9 @@ namespace MontoyaTech.Rest.Net
///
public RouteInclude(Type type)
{
+ if (type == null)
+ throw new ArgumentNullException($"{nameof(type)} cannot be null.");
+
this.Type = type;
}
}
diff --git a/Rest.Net/RouteRequest.cs b/Rest.Net/RouteRequest.cs
index 3d43907..11a4289 100644
--- a/Rest.Net/RouteRequest.cs
+++ b/Rest.Net/RouteRequest.cs
@@ -38,6 +38,9 @@ namespace MontoyaTech.Rest.Net
///
public RouteRequest(Type requestType)
{
+ if (requestType == null)
+ throw new ArgumentNullException($"{nameof(requestType)} cannot be null.");
+
this.RequestType = requestType;
}
}
diff --git a/Rest.Net/RouteResponse.cs b/Rest.Net/RouteResponse.cs
index 583c397..0474440 100644
--- a/Rest.Net/RouteResponse.cs
+++ b/Rest.Net/RouteResponse.cs
@@ -43,6 +43,9 @@ namespace MontoyaTech.Rest.Net
///
public RouteResponse(Type responseType)
{
+ if (responseType == null)
+ throw new ArgumentNullException($"{nameof(responseType)} cannot be null.");
+
this.ResponseType = responseType;
}
}
diff --git a/Rest.Net/RouteTypeName.cs b/Rest.Net/RouteTypeName.cs
index 0aec94d..f2948f1 100644
--- a/Rest.Net/RouteTypeName.cs
+++ b/Rest.Net/RouteTypeName.cs
@@ -17,8 +17,15 @@ namespace MontoyaTech.Rest.Net
///
public string Name;
+ ///
+ /// Creates a new RouteTypeName with the new name to use.
+ ///
+ ///
public RouteTypeName(string name)
{
+ if (string.IsNullOrWhiteSpace(name))
+ throw new ArgumentException($"{nameof(name)} cannot be null or empty.");
+
this.Name = name;
}
}
diff --git a/Rest.Net/StringExtensions.cs b/Rest.Net/StringExtensions.cs
index a2fe900..d6939bf 100644
--- a/Rest.Net/StringExtensions.cs
+++ b/Rest.Net/StringExtensions.cs
@@ -6,8 +6,17 @@ using System.Threading.Tasks;
namespace MontoyaTech.Rest.Net
{
+ ///
+ /// A list of helper extensions for when working with strings.
+ ///
internal static class StringExtensions
{
+ ///
+ /// Counts the occurance of a character in a string and returns it.
+ ///
+ ///
+ ///
+ ///
public static int Count(this string input, char c)
{
int count = 0;
@@ -19,7 +28,13 @@ namespace MontoyaTech.Rest.Net
return count;
}
- public static string Separate(this IList input, char separator)
+ ///
+ /// Concats a list of strings and separates them by a given separator character.
+ ///
+ ///
+ ///
+ ///
+ public static string Concat(this IList input, char separator)
{
if (input == null || input.Count == 0)
return "";
@@ -36,7 +51,13 @@ namespace MontoyaTech.Rest.Net
return builder.ToString();
}
- public static string Separate(this IList input, string separator)
+ ///
+ /// Concats a list of strings and separates them by a given separator string.
+ ///
+ ///
+ ///
+ ///
+ public static string Concat(this IList input, string separator)
{
if (input == null || input.Count == 0)
return "";
@@ -48,7 +69,10 @@ namespace MontoyaTech.Rest.Net
builder.Append(input[0]);
for (int i = 1; i < input.Count; i++)
- builder.Append(separator).Append(input[i]);
+ if (separator != null)
+ builder.Append(separator).Append(input[i]);
+ else
+ builder.Append(input[i]);
return builder.ToString();
}