diff --git a/websocket-sharp/Ext.cs b/websocket-sharp/Ext.cs
index d2a9ca21..4b2b7610 100644
--- a/websocket-sharp/Ext.cs
+++ b/websocket-sharp/Ext.cs
@@ -1,8 +1,8 @@
#region License
/*
* Ext.cs
- * IsPredefinedScheme and MaybeUri methods derived from System.Uri.cs
- * GetStatusDescription method derived from System.Net.HttpListenerResponse.cs
+ * IsPredefinedScheme and MaybeUri methods are derived from System.Uri.cs
+ * GetStatusDescription method is derived from System.Net.HttpListenerResponse.cs
*
* The MIT License
*
@@ -50,13 +50,13 @@ using System.Text;
using WebSocketSharp.Net;
using WebSocketSharp.Net.WebSockets;
-namespace WebSocketSharp {
-
+namespace WebSocketSharp
+{
///
/// Provides a set of static methods for the websocket-sharp.
///
- public static class Ext {
-
+ public static class Ext
+ {
#region Private Const Fields
private const string _tspecials = "()<>@,;:\\\"/[]?={} \t";
@@ -65,164 +65,164 @@ namespace WebSocketSharp {
#region Private Methods
- private static byte[] compress(this byte[] value)
+ private static byte [] compress (this byte [] value)
{
if (value.LongLength == 0)
- //return new Byte[] { 0x00, 0x00, 0x00, 0xff, 0xff };
+ //return new Byte [] { 0x00, 0x00, 0x00, 0xff, 0xff };
return value;
- using (var input = new MemoryStream(value))
+ using (var input = new MemoryStream (value))
{
- return input.compressToArray();
+ return input.compressToArray ();
}
}
- private static MemoryStream compress(this Stream stream)
+ private static MemoryStream compress (this Stream stream)
{
- var output = new MemoryStream();
+ var output = new MemoryStream ();
if (stream.Length == 0)
return output;
stream.Position = 0;
- using (var ds = new DeflateStream(output, CompressionMode.Compress, true))
+ using (var ds = new DeflateStream (output, CompressionMode.Compress, true))
{
- stream.CopyTo(ds);
- ds.Close(); // "BFINAL" set to 1.
+ stream.CopyTo (ds);
+ ds.Close (); // "BFINAL" set to 1.
output.Position = 0;
return output;
}
}
- private static byte[] compressToArray(this Stream stream)
+ private static byte [] compressToArray (this Stream stream)
{
- using (var comp = stream.compress())
+ using (var comp = stream.compress ())
{
- comp.Close();
- return comp.ToArray();
+ comp.Close ();
+ return comp.ToArray ();
}
}
- private static byte[] decompress(this byte[] value)
+ private static byte [] decompress (this byte [] value)
{
if (value.LongLength == 0)
return value;
- using (var input = new MemoryStream(value))
+ using (var input = new MemoryStream (value))
{
- return input.decompressToArray();
+ return input.decompressToArray ();
}
}
- private static MemoryStream decompress(this Stream stream)
+ private static MemoryStream decompress (this Stream stream)
{
- var output = new MemoryStream();
+ var output = new MemoryStream ();
if (stream.Length == 0)
return output;
stream.Position = 0;
- using (var ds = new DeflateStream(stream, CompressionMode.Decompress, true))
+ using (var ds = new DeflateStream (stream, CompressionMode.Decompress, true))
{
- ds.CopyTo(output, true);
+ ds.CopyTo (output, true);
return output;
}
}
- private static byte[] decompressToArray(this Stream stream)
+ private static byte [] decompressToArray (this Stream stream)
{
- using (var decomp = stream.decompress())
+ using (var decomp = stream.decompress ())
{
- decomp.Close();
- return decomp.ToArray();
+ decomp.Close ();
+ return decomp.ToArray ();
}
}
- private static void times(this ulong n, Action act)
+ private static void times (this ulong n, Action act)
{
for (ulong i = 0; i < n; i++)
- act();
+ act ();
}
#endregion
#region Internal Methods
- internal static byte[] Append(this ushort code, string reason)
+ internal static byte [] Append (this ushort code, string reason)
{
- using (var buffer = new MemoryStream())
+ using (var buffer = new MemoryStream ())
{
- var tmp = code.ToByteArray(ByteOrder.BIG);
- buffer.Write(tmp, 0, 2);
+ var tmp = code.ToByteArray (ByteOrder.BIG);
+ buffer.Write (tmp, 0, 2);
if (reason != null && reason.Length > 0)
{
- tmp = Encoding.UTF8.GetBytes(reason);
- buffer.Write(tmp, 0, tmp.Length);
+ tmp = Encoding.UTF8.GetBytes (reason);
+ buffer.Write (tmp, 0, tmp.Length);
}
- buffer.Close();
- return buffer.ToArray();
+ buffer.Close ();
+ return buffer.ToArray ();
}
}
- internal static byte[] Compress(this byte[] value, CompressionMethod method)
+ internal static byte [] Compress (this byte [] value, CompressionMethod method)
{
return method == CompressionMethod.DEFLATE
- ? value.compress()
+ ? value.compress ()
: value;
}
- internal static Stream Compress(this Stream stream, CompressionMethod method)
+ internal static Stream Compress (this Stream stream, CompressionMethod method)
{
return method == CompressionMethod.DEFLATE
- ? stream.compress()
+ ? stream.compress ()
: stream;
}
- internal static byte[] CompressToArray(this Stream stream, CompressionMethod method)
+ internal static byte [] CompressToArray (this Stream stream, CompressionMethod method)
{
return method == CompressionMethod.DEFLATE
- ? stream.compressToArray()
- : stream.ToByteArray();
+ ? stream.compressToArray ()
+ : stream.ToByteArray ();
}
- internal static void CopyTo(this Stream src, Stream dest)
+ internal static void CopyTo (this Stream src, Stream dest)
{
- src.CopyTo(dest, false);
+ src.CopyTo (dest, false);
}
- internal static void CopyTo(this Stream src, Stream dest, bool setDefaultPosition)
+ internal static void CopyTo (this Stream src, Stream dest, bool setDefaultPosition)
{
var readLen = 0;
var bufferLen = 256;
- var buffer = new byte[bufferLen];
- while ((readLen = src.Read(buffer, 0, bufferLen)) > 0)
+ var buffer = new byte [bufferLen];
+ while ((readLen = src.Read (buffer, 0, bufferLen)) > 0)
{
- dest.Write(buffer, 0, readLen);
+ dest.Write (buffer, 0, readLen);
}
if (setDefaultPosition)
dest.Position = 0;
}
- internal static byte[] Decompress(this byte[] value, CompressionMethod method)
+ internal static byte [] Decompress (this byte [] value, CompressionMethod method)
{
return method == CompressionMethod.DEFLATE
- ? value.decompress()
+ ? value.decompress ()
: value;
}
- internal static Stream Decompress(this Stream stream, CompressionMethod method)
+ internal static Stream Decompress (this Stream stream, CompressionMethod method)
{
return method == CompressionMethod.DEFLATE
- ? stream.decompress()
+ ? stream.decompress ()
: stream;
}
- internal static byte[] DecompressToArray(this Stream stream, CompressionMethod method)
+ internal static byte [] DecompressToArray (this Stream stream, CompressionMethod method)
{
return method == CompressionMethod.DEFLATE
- ? stream.decompressToArray()
- : stream.ToByteArray();
+ ? stream.decompressToArray ()
+ : stream.ToByteArray ();
}
internal static bool Equals (this string value, CompressionMethod method)
@@ -250,48 +250,47 @@ namespace WebSocketSharp {
//
// is less than 0, or greater than 255.
//
- internal static bool EqualsWith(this int value, char c, Action action)
+ internal static bool EqualsWith (this int value, char c, Action action)
{
if (value < 0 || value > 255)
- throw new ArgumentOutOfRangeException("value");
+ throw new ArgumentOutOfRangeException ("value");
- action(value);
+ action (value);
return value == c - 0;
}
- internal static string GetNameInternal(this string nameAndValue, string separator)
+ internal static string GetNameInternal (this string nameAndValue, string separator)
{
- int i = nameAndValue.IndexOf(separator);
+ int i = nameAndValue.IndexOf (separator);
return i > 0
- ? nameAndValue.Substring(0, i).Trim()
+ ? nameAndValue.Substring (0, i).Trim ()
: null;
}
- internal static string GetMessage(this CloseStatusCode code)
+ internal static string GetMessage (this CloseStatusCode code)
{
if (code == CloseStatusCode.ABNORMAL)
return "What we've got here is a failure to communicate in the WebSocket protocol.";
if (code == CloseStatusCode.TOO_BIG)
- return String.Format(
- "The size of received payload data is bigger than the allowable value ({0} bytes).",
+ return String.Format ("The size of received payload data is bigger than the allowable value ({0} bytes).",
PayloadData.MaxLength);
return String.Empty;
}
- internal static string GetValueInternal(this string nameAndValue, string separator)
+ internal static string GetValueInternal (this string nameAndValue, string separator)
{
- int i = nameAndValue.IndexOf(separator);
+ int i = nameAndValue.IndexOf (separator);
return i >= 0 && i < nameAndValue.Length - 1
- ? nameAndValue.Substring(i + 1).Trim()
+ ? nameAndValue.Substring (i + 1).Trim ()
: null;
}
- internal static TcpListenerWebSocketContext GetWebSocketContext(
+ internal static TcpListenerWebSocketContext GetWebSocketContext (
this TcpClient client, bool secure, X509Certificate cert)
{
- return new TcpListenerWebSocketContext(client, secure, cert);
+ return new TcpListenerWebSocketContext (client, secure, cert);
}
internal static bool IsCompressionExtension (this string value)
@@ -299,59 +298,13 @@ namespace WebSocketSharp {
return value.StartsWith ("permessage-");
}
- //
- // Determines whether the specified object is .
- //
- //
- // true if is ; otherwise, false.
- //
- //
- // An object to test.
- //
- //
- // The type of parameter.
- //
- internal static bool IsNull(this T obj)
- where T : class
- {
- return obj == null;
- }
-
- //
- // Determines whether the specified object is ,
- // and invokes the specified delegate if the object is .
- //
- //
- // true if is ; otherwise, false.
- //
- //
- // A class to test.
- //
- //
- // An delegate that references the method(s) called if is .
- //
- //
- // The type of .
- //
- internal static bool IsNullDo(this T obj, Action action)
- where T : class
- {
- if (obj == null)
- {
- action();
- return true;
- }
-
- return false;
- }
-
- internal static bool IsText(this string value)
+ internal static bool IsText (this string value)
{
int len = value.Length;
for (int i = 0; i < len; i++)
{
- char c = value[i];
- if (c < 0x20 && !"\r\n\t".Contains(c))
+ char c = value [i];
+ if (c < 0x20 && !"\r\n\t".Contains (c))
return false;
if (c == 0x7f)
@@ -359,8 +312,8 @@ namespace WebSocketSharp {
if (c == '\n' && ++i < len)
{
- c = value[i];
- if (!" \t".Contains(c))
+ c = value [i];
+ if (!" \t".Contains (c))
return false;
}
}
@@ -368,33 +321,33 @@ namespace WebSocketSharp {
return true;
}
- internal static bool IsToken(this string value)
+ internal static bool IsToken (this string value)
{
foreach (char c in value)
- if (c < 0x20 || c >= 0x7f || _tspecials.Contains(c))
+ if (c < 0x20 || c >= 0x7f || _tspecials.Contains (c))
return false;
return true;
}
- internal static string Quote(this string value)
+ internal static string Quote (this string value)
{
- return value.IsToken()
+ return value.IsToken ()
? value
- : String.Format("\"{0}\"", value.Replace("\"", "\\\""));
+ : String.Format ("\"{0}\"", value.Replace ("\"", "\\\""));
}
- internal static byte[] ReadBytesInternal(this Stream stream, int length)
+ internal static byte [] ReadBytesInternal (this Stream stream, int length)
{
- var buffer = new byte[length];
- var readLen = stream.Read(buffer, 0, length);
+ var buffer = new byte [length];
+ var readLen = stream.Read (buffer, 0, length);
if (readLen <= 0)
- return new byte[]{};
+ return new byte [] {};
var tmpLen = 0;
while (readLen < length)
{
- tmpLen = stream.Read(buffer, readLen, length - readLen);
+ tmpLen = stream.Read (buffer, readLen, length - readLen);
if (tmpLen <= 0)
break;
@@ -403,43 +356,43 @@ namespace WebSocketSharp {
return readLen == length
? buffer
- : buffer.SubArray(0, readLen);
+ : buffer.SubArray (0, readLen);
}
- internal static byte[] ReadBytesInternal(this Stream stream, long length, int bufferLength)
+ internal static byte [] ReadBytesInternal (this Stream stream, long length, int bufferLength)
{
var count = length / bufferLength;
var rem = length % bufferLength;
- using (var readData = new MemoryStream())
+ using (var readData = new MemoryStream ())
{
var readLen = 0;
var bufferLen = 0;
var tmpLen = 0;
- Func read = buffer =>
+ Func read = buffer =>
{
bufferLen = buffer.Length;
- readLen = stream.Read(buffer, 0, bufferLen);
+ readLen = stream.Read (buffer, 0, bufferLen);
if (readLen <= 0)
return false;
while (readLen < bufferLen)
{
- tmpLen = stream.Read(buffer, readLen, bufferLen - readLen);
+ tmpLen = stream.Read (buffer, readLen, bufferLen - readLen);
if (tmpLen <= 0)
break;
readLen += tmpLen;
}
- readData.Write(buffer, 0, readLen);
+ readData.Write (buffer, 0, readLen);
return readLen == bufferLen;
};
- var readBuffer = new byte[bufferLength];
+ var readBuffer = new byte [bufferLength];
var readEnd = false;
for (long i = 0; i < count; i++)
{
- if (!read(readBuffer))
+ if (!read (readBuffer))
{
readEnd = true;
break;
@@ -447,19 +400,19 @@ namespace WebSocketSharp {
}
if (!readEnd && rem > 0)
- read(new byte[rem]);
+ read (new byte [rem]);
- readData.Close();
- return readData.ToArray();
+ readData.Close ();
+ return readData.ToArray ();
}
}
- internal static string RemovePrefix(this string value, params string[] prefixes)
+ internal static string RemovePrefix (this string value, params string [] prefixes)
{
int i = 0;
foreach (var prefix in prefixes)
{
- if (value.StartsWith(prefix))
+ if (value.StartsWith (prefix))
{
i = prefix.Length;
break;
@@ -467,20 +420,20 @@ namespace WebSocketSharp {
}
return i > 0
- ? value.Substring(i)
+ ? value.Substring (i)
: value;
}
- internal static IEnumerable SplitHeaderValue(this string value, params char[] separator)
+ internal static IEnumerable SplitHeaderValue (this string value, params char [] separator)
{
- var separators = new string(separator);
- var buffer = new StringBuilder(64);
+ var separators = new string (separator);
+ var buffer = new StringBuilder (64);
int len = value.Length;
bool quoted = false;
bool escaped = false;
for (int i = 0; i < len; i++)
{
- char c = value[i];
+ char c = value [i];
if (c == '"')
{
if (escaped)
@@ -490,14 +443,14 @@ namespace WebSocketSharp {
}
else if (c == '\\')
{
- if (i < len - 1 && value[i + 1] == '"')
+ if (i < len - 1 && value [i + 1] == '"')
escaped = true;
}
- else if (separators.Contains(c))
+ else if (separators.Contains (c))
{
if (!quoted)
{
- yield return buffer.ToString();
+ yield return buffer.ToString ();
buffer.Length = 0;
continue;
}
@@ -505,22 +458,22 @@ namespace WebSocketSharp {
else {
}
- buffer.Append(c);
+ buffer.Append (c);
}
if (buffer.Length > 0)
- yield return buffer.ToString();
+ yield return buffer.ToString ();
}
- internal static byte[] ToByteArray(this Stream stream)
+ internal static byte [] ToByteArray (this Stream stream)
{
- using (var output = new MemoryStream())
+ using (var output = new MemoryStream ())
{
stream.Position = 0;
- stream.CopyTo(output);
- output.Close();
+ stream.CopyTo (output);
+ output.Close ();
- return output.ToArray();
+ return output.ToArray ();
}
}
@@ -540,24 +493,21 @@ namespace WebSocketSharp {
return CompressionMethod.NONE;
}
- internal static string Unquote(this string value)
+ internal static string Unquote (this string value)
{
- var start = value.IndexOf('\"');
- var end = value.LastIndexOf('\"');
+ var start = value.IndexOf ('\"');
+ var end = value.LastIndexOf ('\"');
if (start < end)
- {
- value = value.Substring(start + 1, end - start - 1)
- .Replace("\\\"", "\"");
- }
+ value = value.Substring (start + 1, end - start - 1).Replace ("\\\"", "\"");
- return value.Trim();
+ return value.Trim ();
}
- internal static void WriteBytes(this Stream stream, byte[] value)
+ internal static void WriteBytes (this Stream stream, byte [] value)
{
- using (var input = new MemoryStream(value))
+ using (var input = new MemoryStream (value))
{
- input.CopyTo(stream);
+ input.CopyTo (stream);
}
}
@@ -570,7 +520,8 @@ namespace WebSocketSharp {
/// in the specified array of .
///
///
- /// true if contains any of ; otherwise, false.
+ /// true if contains any of ;
+ /// otherwise, false.
///
///
/// A to test.
@@ -578,13 +529,13 @@ namespace WebSocketSharp {
///
/// An array of that contains characters to find.
///
- public static bool Contains(this string value, params char[] chars)
+ public static bool Contains (this string value, params char [] chars)
{
return chars.Length == 0
? true
: value == null || value.Length == 0
? false
- : value.IndexOfAny(chars) != -1;
+ : value.IndexOfAny (chars) != -1;
}
///
@@ -596,16 +547,16 @@ namespace WebSocketSharp {
/// otherwise, false.
///
///
- /// A that contains the entries.
+ /// A to test.
///
///
/// A that contains the key of the entry to find.
///
- public static bool Contains(this NameValueCollection collection, string name)
+ public static bool Contains (this NameValueCollection collection, string name)
{
return collection == null
? false
- : collection[name] != null;
+ : collection [name] != null;
}
///
@@ -613,11 +564,11 @@ namespace WebSocketSharp {
/// with the specified both and .
///
///
- /// true if contains the entry with both and ;
- /// otherwise, false.
+ /// true if contains the entry with both
+ /// and ; otherwise, false.
///
///
- /// A that contains the entries.
+ /// A to test.
///
///
/// A that contains the key of the entry to find.
@@ -625,49 +576,49 @@ namespace WebSocketSharp {
///
/// A that contains the value of the entry to find.
///
- public static bool Contains(this NameValueCollection collection, string name, string value)
+ public static bool Contains (this NameValueCollection collection, string name, string value)
{
if (collection == null)
return false;
- var values = collection[name];
+ var values = collection [name];
if (values == null)
return false;
- foreach (string v in values.Split(','))
- if (v.Trim().Equals(value, StringComparison.OrdinalIgnoreCase))
+ foreach (string v in values.Split (','))
+ if (v.Trim ().Equals (value, StringComparison.OrdinalIgnoreCase))
return true;
return false;
}
///
- /// Emit the specified delegate if is not .
+ /// Emits the specified delegate if not .
///
///
- /// An to emit.
+ /// A to emit.
///
///
- /// An that emits the .
+ /// An from which emits this .
///
///
- /// An that contains no event data.
+ /// A that contains no event data.
///
- public static void Emit(
+ public static void Emit (
this EventHandler eventHandler, object sender, EventArgs e)
{
if (eventHandler != null)
- eventHandler(sender, e);
+ eventHandler (sender, e);
}
///
- /// Emit the specified EventHandler<TEventArgs> delegate if is not .
+ /// Emits the specified EventHandler<TEventArgs> delegate if not .
///
///
/// An EventHandler<TEventArgs> to emit.
///
///
- /// An that emits the .
+ /// An from which emits this .
///
///
/// A TEventArgs that contains the event data.
@@ -675,24 +626,25 @@ namespace WebSocketSharp {
///
/// The type of the event data generated by the event.
///
- public static void Emit(
+ public static void Emit (
this EventHandler eventHandler, object sender, TEventArgs e)
where TEventArgs : EventArgs
{
if (eventHandler != null)
- eventHandler(sender, e);
+ eventHandler (sender, e);
}
///
/// Gets the absolute path from the specified .
///
///
- /// A that contains the absolute path if got successfully; otherwise, .
+ /// A that contains the absolute path if gets successfully;
+ /// otherwise, .
///
///
- /// A that contains the URI to get the absolute path from.
+ /// A that contains a URI to get the absolute path from.
///
- public static string GetAbsolutePath(this Uri uri)
+ public static string GetAbsolutePath (this Uri uri)
{
if (uri == null)
return null;
@@ -701,13 +653,13 @@ namespace WebSocketSharp {
return uri.AbsolutePath;
var uriString = uri.OriginalString;
- var i = uriString.IndexOf('/');
+ var i = uriString.IndexOf ('/');
if (i != 0)
return null;
- i = uriString.IndexOfAny(new []{'?', '#'});
+ i = uriString.IndexOfAny (new [] {'?', '#'});
return i > 0
- ? uriString.Substring(0, i)
+ ? uriString.Substring (0, i)
: uriString;
}
@@ -724,26 +676,26 @@ namespace WebSocketSharp {
/// true if gets from the response ;
/// from the request , false.
///
- public static CookieCollection GetCookies(this NameValueCollection headers, bool response)
+ public static CookieCollection GetCookies (this NameValueCollection headers, bool response)
{
var name = response ? "Set-Cookie" : "Cookie";
- return headers == null || !headers.Contains(name)
- ? new CookieCollection()
- : CookieCollection.Parse(headers[name], response);
+ return headers == null || !headers.Contains (name)
+ ? new CookieCollection ()
+ : CookieCollection.Parse (headers [name], response);
}
///
- /// Gets the description of the HTTP status code using the specified .
+ /// Gets the description of the HTTP status code using the specified .
///
///
- /// A that contains the description of the HTTP status code.
+ /// A that contains the description of an HTTP status code.
///
///
- /// One of values that contains an HTTP status code.
+ /// One of values that indicates an HTTP status code.
///
- public static string GetDescription(this HttpStatusCode code)
+ public static string GetDescription (this HttpStatusCode code)
{
- return ((int)code).GetStatusDescription();
+ return ((int) code).GetStatusDescription ();
}
///
@@ -759,45 +711,46 @@ namespace WebSocketSharp {
///
/// A that contains a separator string.
///
- public static string GetName(this string nameAndValue, string separator)
+ public static string GetName (this string nameAndValue, string separator)
{
return (nameAndValue != null && nameAndValue.Length != 0) &&
(separator != null && separator.Length != 0)
- ? nameAndValue.GetNameInternal(separator)
+ ? nameAndValue.GetNameInternal (separator)
: null;
}
///
- /// Gets the name and value from the specified that contains a pair of name and value are separated by a separator string.
+ /// Gets the name and value from the specified that contains a pair of name and value
+ /// separated by a separator string.
///
///
/// A KeyValuePair<string, string> that contains the name and value if any.
///
///
- /// A that contains a pair of name and value are separated by a separator string.
+ /// A that contains a pair of name and value separated by a separator string.
///
///
/// A that contains a separator string.
///
- public static KeyValuePair GetNameAndValue(this string nameAndValue, string separator)
+ public static KeyValuePair GetNameAndValue (this string nameAndValue, string separator)
{
- var name = nameAndValue.GetName(separator);
- var value = nameAndValue.GetValue(separator);
+ var name = nameAndValue.GetName (separator);
+ var value = nameAndValue.GetValue (separator);
return name != null
- ? new KeyValuePair(name, value)
- : new KeyValuePair(null, null);
+ ? new KeyValuePair (name, value)
+ : new KeyValuePair (null, null);
}
///
/// Gets the description of the HTTP status code using the specified .
///
///
- /// A that contains the description of the HTTP status code.
+ /// A that contains the description of an HTTP status code.
///
///
/// An that contains an HTTP status code.
///
- public static string GetStatusDescription(this int code)
+ public static string GetStatusDescription (this int code)
{
switch (code)
{
@@ -865,11 +818,11 @@ namespace WebSocketSharp {
///
/// A that contains a separator string.
///
- public static string GetValue(this string nameAndValue, string separator)
+ public static string GetValue (this string nameAndValue, string separator)
{
return (nameAndValue != null && nameAndValue.Length != 0) &&
(separator != null && separator.Length != 0)
- ? nameAndValue.GetValueInternal(separator)
+ ? nameAndValue.GetValueInternal (separator)
: null;
}
@@ -898,7 +851,7 @@ namespace WebSocketSharp {
///
/// A to test.
///
- public static bool IsCloseStatusCode(this ushort code)
+ public static bool IsCloseStatusCode (this ushort code)
{
return code < 1000
? false
@@ -907,20 +860,6 @@ namespace WebSocketSharp {
: true;
}
- ///
- /// Determines whether the specified is empty.
- ///
- ///
- /// true if is empty; otherwise, false.
- ///
- ///
- /// A to test.
- ///
- public static bool IsEmpty(this string value)
- {
- return value.Length == 0;
- }
-
///
/// Determines whether the specified is enclosed in the specified .
///
@@ -933,23 +872,23 @@ namespace WebSocketSharp {
///
/// A that contains character to find.
///
- public static bool IsEnclosedIn(this string value, char c)
+ public static bool IsEnclosedIn (this string value, char c)
{
return value == null || value.Length == 0
? false
- : value[0] == c && value[value.Length - 1] == c;
+ : value [0] == c && value [value.Length - 1] == c;
}
///
- /// Determines whether the specified is host (this computer architecture) byte order.
+ /// Determines whether the specified is host (this computer architecture) byte order.
///
///
- /// true if the parameter is host byte order; otherwise, false.
+ /// true if is host byte order; otherwise, false.
///
///
- /// A to test.
+ /// A to test.
///
- public static bool IsHostOrder(this ByteOrder order)
+ public static bool IsHostOrder (this ByteOrder order)
{
// true : !(true ^ true) or !(false ^ false)
// false: !(true ^ false) or !(false ^ true)
@@ -968,18 +907,18 @@ namespace WebSocketSharp {
///
/// is .
///
- public static bool IsLocal(this System.Net.IPAddress address)
+ public static bool IsLocal (this System.Net.IPAddress address)
{
if (address == null)
- throw new ArgumentNullException("address");
+ throw new ArgumentNullException ("address");
- if (System.Net.IPAddress.IsLoopback(address))
+ if (System.Net.IPAddress.IsLoopback (address))
return true;
- var host = System.Net.Dns.GetHostName();
- var addrs = System.Net.Dns.GetHostAddresses(host);
+ var host = System.Net.Dns.GetHostName ();
+ var addrs = System.Net.Dns.GetHostAddresses (host);
foreach (var addr in addrs)
- if (address.Equals(addr))
+ if (address.Equals (addr))
return true;
return false;
@@ -989,65 +928,58 @@ namespace WebSocketSharp {
/// Determines whether the specified is or empty.
///
///
- /// true if the parameter is or empty; otherwise, false.
+ /// true if is or empty; otherwise, false.
///
///
/// A to test.
///
- public static bool IsNullOrEmpty(this string value)
+ public static bool IsNullOrEmpty (this string value)
{
return value == null || value.Length == 0;
}
///
- /// Determines whether the specified is predefined scheme.
+ /// Determines whether the specified is a predefined scheme.
///
///
- /// true if the parameter is the predefined scheme; otherwise, false.
+ /// true if is a predefined scheme; otherwise, false.
///
///
/// A to test.
///
- public static bool IsPredefinedScheme(this string scheme)
+ public static bool IsPredefinedScheme (this string scheme)
{
if (scheme == null && scheme.Length < 2)
return false;
- char c = scheme[0];
+ char c = scheme [0];
if (c == 'h')
- return (scheme == "http" || scheme == "https");
+ return scheme == "http" || scheme == "https";
if (c == 'f')
- return (scheme == "file" || scheme == "ftp");
+ return scheme == "file" || scheme == "ftp";
if (c == 'w')
- return (scheme == "ws" || scheme == "wss");
+ return scheme == "ws" || scheme == "wss";
if (c == 'n')
{
- c = scheme[1];
- if (c == 'e')
- return (scheme == "news" || scheme == "net.pipe" || scheme == "net.tcp");
-
- if (scheme == "nntp")
- return true;
-
- return false;
+ c = scheme [1];
+ return c == 'e'
+ ? scheme == "news" || scheme == "net.pipe" || scheme == "net.tcp"
+ : scheme == "nntp";
}
- if ((c == 'g' && scheme == "gopher") || (c == 'm' && scheme == "mailto"))
- return true;
-
- return false;
+ return (c == 'g' && scheme == "gopher") || (c == 'm' && scheme == "mailto");
}
///
- /// Determines whether the specified is the HTTP Upgrade request
+ /// Determines whether the specified is an HTTP Upgrade request
/// to switch to the specified .
///
///
- /// true if the specified is the HTTP Upgrade request
- /// to switch to the specified ; otherwise, false.
+ /// true if is an HTTP Upgrade request
+ /// to switch to ; otherwise, false.
///
///
/// A that contains an HTTP request information.
@@ -1056,52 +988,47 @@ namespace WebSocketSharp {
/// A that contains a protocol name.
///
///
- ///
- /// is .
- ///
- ///
- /// -or-
- ///
- ///
- /// is .
- ///
+ ///
+ /// is .
+ ///
+ ///
+ /// -or-
+ ///
+ ///
+ /// is .
+ ///
///
///
/// is .
///
- public static bool IsUpgradeTo(this HttpListenerRequest request, string protocol)
+ public static bool IsUpgradeTo (this HttpListenerRequest request, string protocol)
{
if (request == null)
- throw new ArgumentNullException("request");
+ throw new ArgumentNullException ("request");
if (protocol == null)
- throw new ArgumentNullException("protocol");
+ throw new ArgumentNullException ("protocol");
if (protocol.Length == 0)
- throw new ArgumentException("Must not be empty.", "protocol");
+ throw new ArgumentException ("Must not be empty.", "protocol");
- if (!request.Headers.Contains("Upgrade", protocol))
- return false;
-
- if (!request.Headers.Contains("Connection", "Upgrade"))
- return false;
-
- return true;
+ return request.Headers.Contains ("Upgrade", protocol) &&
+ request.Headers.Contains ("Connection", "Upgrade");
}
///
/// Determines whether the specified is valid absolute path.
///
///
- /// true if the parameter is valid absolute path; otherwise, false.
+ /// true if is valid absolute path; otherwise, false.
///
///
/// A to test.
///
///
- /// A that receives a message if the is invalid.
+ /// A that receives a message if is invalid.
///
- public static bool IsValidAbsolutePath(this string absPath, out string message)
+ public static bool IsValidAbsolutePath (this string absPath, out string message)
{
if (absPath == null || absPath.Length == 0)
{
@@ -1109,14 +1036,14 @@ namespace WebSocketSharp {
return false;
}
- var i = absPath.IndexOf('/');
+ var i = absPath.IndexOf ('/');
if (i != 0)
{
message = "Not absolute path: " + absPath;
return false;
}
- i = absPath.IndexOfAny(new []{'?', '#'});
+ i = absPath.IndexOfAny (new [] {'?', '#'});
if (i != -1)
{
message = "Must not contain either or both query and fragment components: " + absPath;
@@ -1131,24 +1058,24 @@ namespace WebSocketSharp {
/// Determines whether the specified is a URI string.
///
///
- /// true if the parameter is maybe a URI string; otherwise, false.
+ /// true if is maybe a URI string; otherwise, false.
///
///
/// A to test.
///
- public static bool MaybeUri(this string uriString)
+ public static bool MaybeUri (this string uriString)
{
if (uriString == null || uriString.Length == 0)
return false;
- int p = uriString.IndexOf(':');
+ int p = uriString.IndexOf (':');
if (p == -1)
return false;
if (p >= 10)
return false;
- return uriString.Substring(0, p).IsPredefinedScheme();
+ return uriString.Substring (0, p).IsPredefinedScheme ();
}
///
@@ -1164,11 +1091,11 @@ namespace WebSocketSharp {
///
/// An that contains the number of bytes to read.
///
- public static byte[] ReadBytes(this Stream stream, int length)
+ public static byte [] ReadBytes (this Stream stream, int length)
{
return stream == null || length < 1
- ? new byte[]{}
- : stream.ReadBytesInternal(length);
+ ? new byte [] {}
+ : stream.ReadBytesInternal (length);
}
///
@@ -1184,17 +1111,18 @@ namespace WebSocketSharp {
///
/// A that contains the number of bytes to read.
///
- public static byte[] ReadBytes(this Stream stream, long length)
+ public static byte [] ReadBytes (this Stream stream, long length)
{
return stream == null || length < 1
- ? new byte[]{}
+ ? new byte [] {}
: length > 1024
- ? stream.ReadBytesInternal(length, 1024)
- : stream.ReadBytesInternal((int)length);
+ ? stream.ReadBytesInternal (length, 1024)
+ : stream.ReadBytesInternal ((int) length);
}
///
- /// Retrieves a sub-array from the specified . A sub-array starts at the specified element position.
+ /// Retrieves a sub-array from the specified .
+ /// A sub-array starts at the specified element position.
///
///
/// An array of T that receives a sub-array, or an empty array of T if any problems with the parameters.
@@ -1203,7 +1131,7 @@ namespace WebSocketSharp {
/// An array of T that contains the data to retrieve a sub-array.
///
///
- /// An that contains the zero-based starting position of a sub-array in the .
+ /// An that contains the zero-based starting position of a sub-array in .
///
///
/// An that contains the number of elements to retrieve a sub-array.
@@ -1211,22 +1139,22 @@ namespace WebSocketSharp {
///
/// The type of elements in the .
///
- public static T[] SubArray(this T[] array, int startIndex, int length)
+ public static T [] SubArray (this T [] array, int startIndex, int length)
{
if (array == null || array.Length == 0)
- return new T[]{};
+ return new T [] {};
if (startIndex < 0 || length <= 0)
- return new T[]{};
+ return new T [] {};
if (startIndex + length > array.Length)
- return new T[]{};
+ return new T [] {};
if (startIndex == 0 && array.Length == length)
return array;
- T[] subArray = new T[length];
- Array.Copy(array, startIndex, subArray, 0, length);
+ T [] subArray = new T [length];
+ Array.Copy (array, startIndex, subArray, 0, length);
return subArray;
}
@@ -1240,10 +1168,10 @@ namespace WebSocketSharp {
///
/// An delegate that references the method(s) to execute.
///
- public static void Times(this int n, Action act)
+ public static void Times (this int n, Action act)
{
if (n > 0 && act != null)
- ((ulong)n).times(act);
+ ((ulong) n).times (act);
}
///
@@ -1255,10 +1183,10 @@ namespace WebSocketSharp {
///
/// An delegate that references the method(s) to execute.
///
- public static void Times(this long n, Action act)
+ public static void Times( this long n, Action act)
{
if (n > 0 && act != null)
- ((ulong)n).times(act);
+ ((ulong) n).times (act);
}
///
@@ -1270,10 +1198,10 @@ namespace WebSocketSharp {
///
/// An delegate that references the method(s) to execute.
///
- public static void Times(this uint n, Action act)
+ public static void Times (this uint n, Action act)
{
if (n > 0 && act != null)
- ((ulong)n).times(act);
+ ((ulong) n).times (act);
}
///
@@ -1285,10 +1213,10 @@ namespace WebSocketSharp {
///
/// An delegate that references the method(s) to execute.
///
- public static void Times(this ulong n, Action act)
+ public static void Times (this ulong n, Action act)
{
if (n > 0 && act != null)
- n.times(act);
+ n.times (act);
}
///
@@ -1301,11 +1229,11 @@ namespace WebSocketSharp {
/// An Action<int> delegate that references the method(s) to execute.
/// An parameter to pass to the method(s) is the zero-based count of iteration.
///
- public static void Times(this int n, Action act)
+ public static void Times (this int n, Action act)
{
if (n > 0 && act != null)
for (int i = 0; i < n; i++)
- act(i);
+ act (i);
}
///
@@ -1318,11 +1246,11 @@ namespace WebSocketSharp {
/// An Action<long> delegate that references the method(s) to execute.
/// A parameter to pass to the method(s) is the zero-based count of iteration.
///
- public static void Times(this long n, Action act)
+ public static void Times (this long n, Action act)
{
if (n > 0 && act != null)
for (long i = 0; i < n; i++)
- act(i);
+ act (i);
}
///
@@ -1335,11 +1263,11 @@ namespace WebSocketSharp {
/// An Action<uint> delegate that references the method(s) to execute.
/// A parameter to pass to the method(s) is the zero-based count of iteration.
///
- public static void Times(this uint n, Action act)
+ public static void Times (this uint n, Action act)
{
if (n > 0 && act != null)
for (uint i = 0; i < n; i++)
- act(i);
+ act (i);
}
///
@@ -1352,11 +1280,11 @@ namespace WebSocketSharp {
/// An Action<ulong> delegate that references the method(s) to execute.
/// A parameter to pass to this method(s) is the zero-based count of iteration.
///
- public static void Times(this ulong n, Action act)
+ public static void Times (this ulong n, Action act)
{
if (n > 0 && act != null)
for (ulong i = 0; i < n; i++)
- act(i);
+ act (i);
}
///
@@ -1373,7 +1301,7 @@ namespace WebSocketSharp {
/// An array of to convert.
///
///
- /// A that indicates the byte order of .
+ /// A that indicates the byte order of .
///
///
/// The type of the return. The T must be a value type.
@@ -1381,39 +1309,39 @@ namespace WebSocketSharp {
///
/// is .
///
- public static T To(this byte[] src, ByteOrder srcOrder)
+ public static T To (this byte [] src, ByteOrder srcOrder)
where T : struct
{
if (src == null)
- throw new ArgumentNullException("src");
+ throw new ArgumentNullException ("src");
if (src.Length == 0)
- return default(T);
+ return default (T);
- var type = typeof(T);
- var buffer = src.ToHostOrder(srcOrder);
+ var type = typeof (T);
+ var buffer = src.ToHostOrder (srcOrder);
- return type == typeof(Boolean)
- ? (T)(object)BitConverter.ToBoolean(buffer, 0)
- : type == typeof(Char)
- ? (T)(object)BitConverter.ToChar(buffer, 0)
- : type == typeof(Double)
- ? (T)(object)BitConverter.ToDouble(buffer, 0)
- : type == typeof(Int16)
- ? (T)(object)BitConverter.ToInt16(buffer, 0)
- : type == typeof(Int32)
- ? (T)(object)BitConverter.ToInt32(buffer, 0)
- : type == typeof(Int64)
- ? (T)(object)BitConverter.ToInt64(buffer, 0)
- : type == typeof(Single)
- ? (T)(object)BitConverter.ToSingle(buffer, 0)
- : type == typeof(UInt16)
- ? (T)(object)BitConverter.ToUInt16(buffer, 0)
- : type == typeof(UInt32)
- ? (T)(object)BitConverter.ToUInt32(buffer, 0)
- : type == typeof(UInt64)
- ? (T)(object)BitConverter.ToUInt64(buffer, 0)
- : default(T);
+ return type == typeof (Boolean)
+ ? (T)(object) BitConverter.ToBoolean (buffer, 0)
+ : type == typeof (Char)
+ ? (T)(object) BitConverter.ToChar (buffer, 0)
+ : type == typeof (Double)
+ ? (T)(object) BitConverter.ToDouble (buffer, 0)
+ : type == typeof (Int16)
+ ? (T)(object) BitConverter.ToInt16 (buffer, 0)
+ : type == typeof (Int32)
+ ? (T)(object) BitConverter.ToInt32 (buffer, 0)
+ : type == typeof (Int64)
+ ? (T)(object) BitConverter.ToInt64 (buffer, 0)
+ : type == typeof (Single)
+ ? (T)(object) BitConverter.ToSingle (buffer, 0)
+ : type == typeof (UInt16)
+ ? (T)(object) BitConverter.ToUInt16 (buffer, 0)
+ : type == typeof (UInt32)
+ ? (T)(object) BitConverter.ToUInt32 (buffer, 0)
+ : type == typeof (UInt64)
+ ? (T)(object) BitConverter.ToUInt64 (buffer, 0)
+ : default (T);
}
///
@@ -1426,42 +1354,42 @@ namespace WebSocketSharp {
/// A T to convert.
///
///
- /// A that indicates the byte order of the return.
+ /// A that indicates the byte order of the return.
///
///
/// The type of . The T must be a value type.
///
- public static byte[] ToByteArray(this T value, ByteOrder order)
+ public static byte [] ToByteArray (this T value, ByteOrder order)
where T : struct
{
- var type = typeof(T);
- var buffer = type == typeof(Boolean)
- ? BitConverter.GetBytes((Boolean)(object)value)
- : type == typeof(Byte)
- ? new byte[]{ (Byte)(object)value }
- : type == typeof(Char)
- ? BitConverter.GetBytes((Char)(object)value)
- : type == typeof(Double)
- ? BitConverter.GetBytes((Double)(object)value)
- : type == typeof(Int16)
- ? BitConverter.GetBytes((Int16)(object)value)
- : type == typeof(Int32)
- ? BitConverter.GetBytes((Int32)(object)value)
- : type == typeof(Int64)
- ? BitConverter.GetBytes((Int64)(object)value)
- : type == typeof(Single)
- ? BitConverter.GetBytes((Single)(object)value)
- : type == typeof(UInt16)
- ? BitConverter.GetBytes((UInt16)(object)value)
- : type == typeof(UInt32)
- ? BitConverter.GetBytes((UInt32)(object)value)
- : type == typeof(UInt64)
- ? BitConverter.GetBytes((UInt64)(object)value)
- : new byte[]{};
+ var type = typeof (T);
+ var buffer = type == typeof (Boolean)
+ ? BitConverter.GetBytes ((Boolean)(object) value)
+ : type == typeof (Byte)
+ ? new byte [] { (Byte)(object) value }
+ : type == typeof (Char)
+ ? BitConverter.GetBytes ((Char)(object) value)
+ : type == typeof (Double)
+ ? BitConverter.GetBytes ((Double)(object) value)
+ : type == typeof (Int16)
+ ? BitConverter.GetBytes ((Int16)(object) value)
+ : type == typeof (Int32)
+ ? BitConverter.GetBytes ((Int32)(object) value)
+ : type == typeof (Int64)
+ ? BitConverter.GetBytes ((Int64)(object) value)
+ : type == typeof (Single)
+ ? BitConverter.GetBytes ((Single)(object) value)
+ : type == typeof (UInt16)
+ ? BitConverter.GetBytes ((UInt16)(object) value)
+ : type == typeof (UInt32)
+ ? BitConverter.GetBytes ((UInt32)(object) value)
+ : type == typeof (UInt64)
+ ? BitConverter.GetBytes ((UInt64)(object) value)
+ : new byte [] {};
- return buffer.Length <= 1 || order.IsHostOrder()
+ return buffer.Length <= 1 || order.IsHostOrder ()
? buffer
- : buffer.Reverse().ToArray();
+ : buffer.Reverse ().ToArray ();
}
///
@@ -1479,14 +1407,14 @@ namespace WebSocketSharp {
///
/// is .
///
- public static byte[] ToHostOrder(this byte[] src, ByteOrder srcOrder)
+ public static byte [] ToHostOrder (this byte [] src, ByteOrder srcOrder)
{
if (src == null)
- throw new ArgumentNullException("src");
+ throw new ArgumentNullException ("src");
- return src.Length <= 1 || srcOrder.IsHostOrder()
+ return src.Length <= 1 || srcOrder.IsHostOrder ()
? src
- : src.Reverse().ToArray();
+ : src.Reverse ().ToArray ();
}
///
@@ -1495,7 +1423,7 @@ namespace WebSocketSharp {
///
///
/// A converted from , or a
- /// if the length of is zero.
+ /// if is empty.
///
///
/// An array of T to convert.
@@ -1509,10 +1437,10 @@ namespace WebSocketSharp {
///
/// is .
///
- public static string ToString(this T[] array, string separator)
+ public static string ToString (this T [] array, string separator)
{
if (array == null)
- throw new ArgumentNullException("array");
+ throw new ArgumentNullException ("array");
var len = array.Length;
if (len == 0)
@@ -1521,56 +1449,58 @@ namespace WebSocketSharp {
if (separator == null)
separator = String.Empty;
- var buffer = new StringBuilder(64);
- (len - 1).Times(i =>
- buffer.AppendFormat("{0}{1}", array[i].ToString(), separator)
+ var buffer = new StringBuilder (64);
+ (len - 1).Times (i =>
+ buffer.AppendFormat ("{0}{1}", array [i].ToString (), separator)
);
- buffer.Append(array[len - 1].ToString());
- return buffer.ToString();
+ buffer.Append (array [len - 1].ToString ());
+ return buffer.ToString ();
}
///
- /// Converts the specified to a object.
+ /// Converts the specified to a .
///
///
- /// A converted from the parameter, or
- /// if the is or .
+ /// A converted from , or
+ /// if is or .
///
///
/// A to convert.
///
- public static Uri ToUri(this string uriString)
+ public static Uri ToUri (this string uriString)
{
return uriString == null || uriString.Length == 0
? null
- : uriString.MaybeUri()
- ? new Uri(uriString)
- : new Uri(uriString, UriKind.Relative);
+ : uriString.MaybeUri ()
+ ? new Uri (uriString)
+ : new Uri (uriString, UriKind.Relative);
}
///
- /// Tries to create a new WebSocket using the specified .
+ /// Tries to create a new WebSocket with the specified .
///
///
- /// true if the WebSocket was successfully created; otherwise, false.
+ /// true if a WebSocket is successfully created; otherwise, false.
///
///
/// A that contains a WebSocket URI.
///
///
- /// When this method returns, contains a created WebSocket if the parameter is valid WebSocket URI; otherwise, .
+ /// When this method returns, contains a created WebSocket
+ /// if is valid WebSocket URI; otherwise, .
///
///
- /// When this method returns, contains a error message if the parameter is invalid WebSocket URI; otherwise, String.Empty.
+ /// When this method returns, contains a error message
+ /// if is invalid WebSocket URI; otherwise, String.Empty.
///
///
- /// Is thrown when the parameter passed to a method is invalid because it is .
+ /// is .
///
- public static bool TryCreateWebSocketUri(this string uriString, out Uri result, out string message)
+ public static bool TryCreateWebSocketUri (this string uriString, out Uri result, out string message)
{
if (uriString == null)
- throw new ArgumentNullException("uriString");
+ throw new ArgumentNullException ("uriString");
result = null;
if (uriString.Length == 0)
@@ -1579,7 +1509,7 @@ namespace WebSocketSharp {
return false;
}
- var uri = uriString.ToUri();
+ var uri = uriString.ToUri ();
if (!uri.IsAbsoluteUri)
{
message = "Not absolute URI: " + uriString;
@@ -1606,21 +1536,18 @@ namespace WebSocketSharp {
if ((scheme == "ws" && port == 443) ||
(scheme == "wss" && port == 80))
{
- message = String.Format(
- "Invalid pair of scheme and port: {0}, {1}", scheme, port);
+ message = String.Format ("Invalid pair of scheme and port: {0}, {1}", scheme, port);
return false;
}
}
else
{
- port = scheme == "ws"
- ? 80
- : 443;
- var url = String.Format("{0}://{1}:{2}{3}", scheme, uri.Host, port, uri.PathAndQuery);
- uri = url.ToUri();
+ port = scheme == "ws" ? 80 : 443;
+ var url = String.Format ("{0}://{1}:{2}{3}", scheme, uri.Host, port, uri.PathAndQuery);
+ uri = url.ToUri ();
}
- result = uri;
+ result = uri;
message = String.Empty;
return true;
@@ -1630,60 +1557,60 @@ namespace WebSocketSharp {
/// URL-decodes the specified .
///
///
- /// A that receives a decoded string, or the parameter
- /// if the is or .
+ /// A that receives a decoded string, or the
+ /// if is or .
///
///
/// A to decode.
///
- public static string UrlDecode(this string s)
+ public static string UrlDecode (this string s)
{
return s == null || s.Length == 0
? s
- : HttpUtility.UrlDecode(s);
+ : HttpUtility.UrlDecode (s);
}
///
/// URL-encodes the specified .
///
///
- /// A that receives a encoded string, or the parameter
- /// if the is or .
+ /// A that receives a encoded string, or the
+ /// if is or .
///
///
/// A to encode.
///
- public static string UrlEncode(this string s)
+ public static string UrlEncode (this string s)
{
return s == null || s.Length == 0
? s
- : HttpUtility.UrlEncode(s);
+ : HttpUtility.UrlEncode (s);
}
///
- /// Writes the specified content data using the specified .
+ /// Writes the specified content data using the specified .
///
///
- /// A that contains a network stream to write a content data.
+ /// A that contains a network stream to write a content data.
///
///
/// An array of that contains a content data to write.
///
///
- /// Is thrown when the parameter passed to a method is invalid because it is .
+ /// is .
///
- public static void WriteContent(this HttpListenerResponse response, byte[] content)
+ public static void WriteContent (this HttpListenerResponse response, byte [] content)
{
if (response == null)
- throw new ArgumentNullException("response");
+ throw new ArgumentNullException ("response");
if (content == null || content.Length == 0)
return;
var output = response.OutputStream;
response.ContentLength64 = content.Length;
- output.Write(content, 0, content.Length);
- output.Close();
+ output.Write (content, 0, content.Length);
+ output.Close ();
}
#endregion
diff --git a/websocket-sharp/Net/Cookie.cs b/websocket-sharp/Net/Cookie.cs
index d8cc016d..0802dad3 100644
--- a/websocket-sharp/Net/Cookie.cs
+++ b/websocket-sharp/Net/Cookie.cs
@@ -37,8 +37,8 @@ using System.Text;
using System.Globalization;
using System.Collections;
-namespace WebSocketSharp.Net {
-
+namespace WebSocketSharp.Net
+{
///
/// Provides a set of properties and methods used to manage an HTTP Cookie.
///
@@ -54,8 +54,8 @@ namespace WebSocketSharp.Net {
///
///
[Serializable]
- public sealed class Cookie {
-
+ public sealed class Cookie
+ {
#region Static Private Fields
static char [] reservedCharsForName = new char [] {' ', '=', ';', ',', '\n', '\r', '\t'};
@@ -270,7 +270,7 @@ namespace WebSocketSharp.Net {
///
public string Comment {
get { return comment; }
- set { comment = value.IsNull () ? String.Empty : value; }
+ set { comment = value ?? String.Empty; }
}
///
@@ -395,7 +395,7 @@ namespace WebSocketSharp.Net {
///
public string Path {
get { return path; }
- set { path = value.IsNull () ? String.Empty : value; }
+ set { path = value ?? String.Empty; }
}
///
@@ -480,9 +480,7 @@ namespace WebSocketSharp.Net {
if (!CanSetValue (value, out msg))
throw new CookieException (msg);
- val = value.IsEmpty ()
- ? "\"\""
- : value;
+ val = value.Length == 0 ? "\"\"" : value;
}
}
@@ -528,7 +526,7 @@ namespace WebSocketSharp.Net {
static bool CanSetValue (string value, out string message)
{
- if (value.IsNull ()) {
+ if (value == null) {
message = "Value must not be null.";
return false;
}
@@ -595,7 +593,7 @@ namespace WebSocketSharp.Net {
if (!comment.IsNullOrEmpty ())
result.AppendFormat ("; Comment={0}", comment.UrlEncode ());
- if (!commentUri.IsNull ())
+ if (commentUri != null)
result.AppendFormat ("; CommentURL={0}", commentUri.OriginalString.Quote ());
if (discard)
@@ -614,7 +612,7 @@ namespace WebSocketSharp.Net {
for (int i = 0; i < values.Length; i++) {
tmp [i] = int.MinValue;
var v = values [i].Trim ();
- if (v.IsEmpty ())
+ if (v.Length == 0)
continue;
if (!int.TryParse (v, out tmp [i])) {
@@ -636,7 +634,7 @@ namespace WebSocketSharp.Net {
// From client to server
internal string ToRequestString (Uri uri)
{
- if (name.IsEmpty ())
+ if (name.Length == 0)
return String.Empty;
if (version == 0)
@@ -646,12 +644,12 @@ namespace WebSocketSharp.Net {
result.AppendFormat ("$Version={0}; {1}={2}", version, name, val);
if (!path.IsNullOrEmpty ())
result.AppendFormat ("; $Path={0}", path);
- else if (!uri.IsNull ())
+ else if (uri != null)
result.AppendFormat ("; $Path={0}", uri.GetAbsolutePath ());
else
result.Append ("; $Path=/");
- bool append_domain = uri.IsNull () || uri.Host != domain;
+ bool append_domain = uri == null || uri.Host != domain;
if (append_domain && !domain.IsNullOrEmpty ())
result.AppendFormat ("; $Domain={0}", domain);
@@ -667,7 +665,7 @@ namespace WebSocketSharp.Net {
// From server to client
internal string ToResponseString ()
{
- return name.IsEmpty ()
+ return name.Length == 0
? String.Empty
: version == 0
? ToResponseStringVersion0 ()
@@ -691,12 +689,12 @@ namespace WebSocketSharp.Net {
public override bool Equals (Object comparand)
{
var cookie = comparand as Cookie;
- return !cookie.IsNull() &&
- name.Equals (cookie.Name, StringComparison.InvariantCultureIgnoreCase) &&
- val.Equals (cookie.Value, StringComparison.InvariantCulture) &&
- path.Equals (cookie.Path, StringComparison.InvariantCulture) &&
- domain.Equals (cookie.Domain, StringComparison.InvariantCultureIgnoreCase) &&
- version == cookie.Version;
+ return cookie != null &&
+ name.Equals (cookie.Name, StringComparison.InvariantCultureIgnoreCase) &&
+ val.Equals (cookie.Value, StringComparison.InvariantCulture) &&
+ path.Equals (cookie.Path, StringComparison.InvariantCulture) &&
+ domain.Equals (cookie.Domain, StringComparison.InvariantCultureIgnoreCase) &&
+ version == cookie.Version;
}
///
diff --git a/websocket-sharp/Net/CookieCollection.cs b/websocket-sharp/Net/CookieCollection.cs
index fe08e9b2..0cfa7203 100644
--- a/websocket-sharp/Net/CookieCollection.cs
+++ b/websocket-sharp/Net/CookieCollection.cs
@@ -179,7 +179,7 @@ namespace WebSocketSharp.Net {
///
public Cookie this [string name] {
get {
- if (name.IsNull ())
+ if (name == null)
throw new ArgumentNullException ("name");
foreach (var cookie in Sorted) {
@@ -199,7 +199,7 @@ namespace WebSocketSharp.Net {
///
public Object SyncRoot {
get {
- if (sync.IsNull ())
+ if (sync == null)
sync = new object ();
return sync;
@@ -219,18 +219,18 @@ namespace WebSocketSharp.Net {
string [] pairs = Split(value).ToArray();
for (int i = 0; i < pairs.Length; i++) {
string pair = pairs [i].Trim ();
- if (pair.IsEmpty ())
+ if (pair.Length == 0)
continue;
if (pair.StartsWith ("$version", StringComparison.InvariantCultureIgnoreCase)) {
version = Int32.Parse (pair.GetValueInternal ("=").Trim ('"'));
}
else if (pair.StartsWith ("$path", StringComparison.InvariantCultureIgnoreCase)) {
- if (!cookie.IsNull ())
+ if (cookie != null)
cookie.Path = pair.GetValueInternal ("=");
}
else if (pair.StartsWith ("$domain", StringComparison.InvariantCultureIgnoreCase)) {
- if (!cookie.IsNull ())
+ if (cookie != null)
cookie.Domain = pair.GetValueInternal ("=");
}
else if (pair.StartsWith ("$port", StringComparison.InvariantCultureIgnoreCase)) {
@@ -238,11 +238,11 @@ namespace WebSocketSharp.Net {
? "\"\""
: pair.GetValueInternal ("=");
- if (!cookie.IsNull ())
+ if (cookie != null)
cookie.Port = port;
}
else {
- if (!cookie.IsNull ())
+ if (cookie != null)
cookies.Add (cookie);
string name;
@@ -265,7 +265,7 @@ namespace WebSocketSharp.Net {
}
}
- if (!cookie.IsNull ())
+ if (cookie != null)
cookies.Add (cookie);
return cookies;
@@ -279,11 +279,11 @@ namespace WebSocketSharp.Net {
string [] pairs = Split(value).ToArray();
for (int i = 0; i < pairs.Length; i++) {
string pair = pairs [i].Trim ();
- if (pair.IsEmpty ())
+ if (pair.Length == 0)
continue;
if (pair.StartsWith ("version", StringComparison.InvariantCultureIgnoreCase)) {
- if (!cookie.IsNull ())
+ if (cookie != null)
cookie.Version = Int32.Parse (pair.GetValueInternal ("=").Trim ('"'));
}
else if (pair.StartsWith ("expires", StringComparison.InvariantCultureIgnoreCase)) {
@@ -299,21 +299,21 @@ namespace WebSocketSharp.Net {
out expires))
expires = DateTime.Now;
- if (!cookie.IsNull () && cookie.Expires == DateTime.MinValue)
+ if (cookie != null && cookie.Expires == DateTime.MinValue)
cookie.Expires = expires.ToLocalTime ();
}
else if (pair.StartsWith ("max-age", StringComparison.InvariantCultureIgnoreCase)) {
int max = Int32.Parse (pair.GetValueInternal ("=").Trim ('"'));
var expires = DateTime.Now.AddSeconds ((double) max);
- if (!cookie.IsNull ())
+ if (cookie != null)
cookie.Expires = expires;
}
else if (pair.StartsWith ("path", StringComparison.InvariantCultureIgnoreCase)) {
- if (!cookie.IsNull ())
+ if (cookie != null)
cookie.Path = pair.GetValueInternal ("=");
}
else if (pair.StartsWith ("domain", StringComparison.InvariantCultureIgnoreCase)) {
- if (!cookie.IsNull ())
+ if (cookie != null)
cookie.Domain = pair.GetValueInternal ("=");
}
else if (pair.StartsWith ("port", StringComparison.InvariantCultureIgnoreCase)) {
@@ -321,31 +321,31 @@ namespace WebSocketSharp.Net {
? "\"\""
: pair.GetValueInternal ("=");
- if (!cookie.IsNull ())
+ if (cookie != null)
cookie.Port = port;
}
else if (pair.StartsWith ("comment", StringComparison.InvariantCultureIgnoreCase)) {
- if (!cookie.IsNull ())
+ if (cookie != null)
cookie.Comment = pair.GetValueInternal ("=").UrlDecode ();
}
else if (pair.StartsWith ("commenturl", StringComparison.InvariantCultureIgnoreCase)) {
- if (!cookie.IsNull ())
+ if (cookie != null)
cookie.CommentUri = pair.GetValueInternal ("=").Trim ('"').ToUri ();
}
else if (pair.StartsWith ("discard", StringComparison.InvariantCultureIgnoreCase)) {
- if (!cookie.IsNull ())
+ if (cookie != null)
cookie.Discard = true;
}
else if (pair.StartsWith ("secure", StringComparison.InvariantCultureIgnoreCase)) {
- if (!cookie.IsNull ())
+ if (cookie != null)
cookie.Secure = true;
}
else if (pair.StartsWith ("httponly", StringComparison.InvariantCultureIgnoreCase)) {
- if (!cookie.IsNull ())
+ if (cookie != null)
cookie.HttpOnly = true;
}
else {
- if (!cookie.IsNull ())
+ if (cookie != null)
cookies.Add (cookie);
string name;
@@ -366,7 +366,7 @@ namespace WebSocketSharp.Net {
}
}
- if (!cookie.IsNull ())
+ if (cookie != null)
cookies.Add (cookie);
return cookies;
@@ -457,7 +457,7 @@ namespace WebSocketSharp.Net {
///
public void Add (Cookie cookie)
{
- if (cookie.IsNull ())
+ if (cookie == null)
throw new ArgumentNullException ("cookie");
int pos = SearchCookie (cookie);
@@ -478,7 +478,7 @@ namespace WebSocketSharp.Net {
///
public void Add (CookieCollection cookies)
{
- if (cookies.IsNull ())
+ if (cookies == null)
throw new ArgumentNullException ("cookies");
foreach (Cookie cookie in cookies)
@@ -519,7 +519,7 @@ namespace WebSocketSharp.Net {
///
public void CopyTo (Array array, int index)
{
- if (array.IsNull ())
+ if (array == null)
throw new ArgumentNullException ("array");
if (index < 0)
@@ -561,7 +561,7 @@ namespace WebSocketSharp.Net {
///
public void CopyTo (Cookie [] array, int index)
{
- if (array.IsNull ())
+ if (array == null)
throw new ArgumentNullException ("array");
if (index < 0)
diff --git a/websocket-sharp/Net/HttpListenerResponse.cs b/websocket-sharp/Net/HttpListenerResponse.cs
index 26a999fb..2463b190 100644
--- a/websocket-sharp/Net/HttpListenerResponse.cs
+++ b/websocket-sharp/Net/HttpListenerResponse.cs
@@ -36,8 +36,8 @@ using System.Linq;
using System.Net;
using System.Text;
-namespace WebSocketSharp.Net {
-
+namespace WebSocketSharp.Net
+{
///
/// Provides access to a response to a request being processed by a instance.
///
@@ -184,10 +184,10 @@ namespace WebSocketSharp.Net {
if (HeadersSent)
throw new InvalidOperationException ("Cannot be changed after headers are sent.");
- if (value.IsNull ())
+ if (value == null)
throw new ArgumentNullException ("value");
- if (value.IsEmpty ())
+ if (value.Length == 0)
throw new ArgumentException ("Must not be empty.", "value");
content_type = value;
@@ -342,7 +342,7 @@ namespace WebSocketSharp.Net {
if (HeadersSent)
throw new InvalidOperationException ("Cannot be changed after headers are sent.");
- if (value.IsEmpty ())
+ if (value.Length == 0)
throw new ArgumentException ("Must not be empty.", "value");
location = value;
@@ -758,7 +758,7 @@ namespace WebSocketSharp.Net {
///
public void SetCookie (Cookie cookie)
{
- if (cookie.IsNull())
+ if (cookie == null)
throw new ArgumentNullException ("cookie");
if (!CanAddOrUpdate (cookie))
diff --git a/websocket-sharp/Net/WebHeaderCollection.cs b/websocket-sharp/Net/WebHeaderCollection.cs
index 27929a9d..cfdbeaa2 100644
--- a/websocket-sharp/Net/WebHeaderCollection.cs
+++ b/websocket-sharp/Net/WebHeaderCollection.cs
@@ -43,15 +43,15 @@ using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Text;
-namespace WebSocketSharp.Net {
-
+namespace WebSocketSharp.Net
+{
///
/// Provides a collection of the HTTP headers associated with a request or response.
///
[Serializable]
[ComVisible (true)]
- public class WebHeaderCollection : NameValueCollection, ISerializable {
-
+ public class WebHeaderCollection : NameValueCollection, ISerializable
+ {
#region Fields
static readonly Dictionary headers;
@@ -275,7 +275,7 @@ namespace WebSocketSharp.Net {
protected WebHeaderCollection (
SerializationInfo serializationInfo, StreamingContext streamingContext)
{
- if (serializationInfo.IsNull ())
+ if (serializationInfo == null)
throw new ArgumentNullException ("serializationInfo");
try {
@@ -582,9 +582,7 @@ namespace WebSocketSharp.Net {
static bool TryGetHeaderInfo (string name, out HttpHeaderInfo info)
{
info = GetHeaderInfo (name);
- return info.IsNull ()
- ? false
- : true;
+ return info != null;
}
#endregion
@@ -932,7 +930,7 @@ namespace WebSocketSharp.Net {
public override string [] GetValues (string header)
{
string [] values = base.GetValues (header);
- return values.IsNull () || values.Length == 0
+ return values == null || values.Length == 0
? null
: values;
}
@@ -949,7 +947,7 @@ namespace WebSocketSharp.Net {
public override string [] GetValues (int index)
{
string [] values = base.GetValues (index);
- return values.IsNull () || values.Length == 0
+ return values == null || values.Length == 0
? null
: values;
}
@@ -971,7 +969,7 @@ namespace WebSocketSharp.Net {
public override void GetObjectData (
SerializationInfo serializationInfo, StreamingContext streamingContext)
{
- if (serializationInfo.IsNull ())
+ if (serializationInfo == null)
throw new ArgumentNullException ("serializationInfo");
serializationInfo.AddValue ("InternallyCreated", internallyCreated);