diff --git a/Example/bin/Debug_Ubuntu/example.exe b/Example/bin/Debug_Ubuntu/example.exe index a92d86d2..f96ac1dd 100755 Binary files a/Example/bin/Debug_Ubuntu/example.exe and b/Example/bin/Debug_Ubuntu/example.exe differ diff --git a/Example/bin/Debug_Ubuntu/websocket-sharp.dll b/Example/bin/Debug_Ubuntu/websocket-sharp.dll index cd7ef85f..0f292a36 100755 Binary files a/Example/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example1/bin/Debug_Ubuntu/example1.exe b/Example1/bin/Debug_Ubuntu/example1.exe index ad90dc78..c053187c 100755 Binary files a/Example1/bin/Debug_Ubuntu/example1.exe and b/Example1/bin/Debug_Ubuntu/example1.exe differ diff --git a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll index cd7ef85f..0f292a36 100755 Binary files a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example2/bin/Debug_Ubuntu/example2.exe b/Example2/bin/Debug_Ubuntu/example2.exe index 2707a2e5..108d9f61 100755 Binary files a/Example2/bin/Debug_Ubuntu/example2.exe and b/Example2/bin/Debug_Ubuntu/example2.exe differ diff --git a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll index cd7ef85f..0f292a36 100755 Binary files a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example3/bin/Debug_Ubuntu/Example3.exe b/Example3/bin/Debug_Ubuntu/Example3.exe index e4e2cb13..87c51f32 100755 Binary files a/Example3/bin/Debug_Ubuntu/Example3.exe and b/Example3/bin/Debug_Ubuntu/Example3.exe differ diff --git a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll index cd7ef85f..0f292a36 100755 Binary files a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/websocket-sharp/Ext.cs b/websocket-sharp/Ext.cs index 8c1bdb87..0a797eb4 100644 --- a/websocket-sharp/Ext.cs +++ b/websocket-sharp/Ext.cs @@ -1362,23 +1362,23 @@ namespace WebSocketSharp { /// Converts the specified array of to the specified type data. /// /// - /// A T converted from the , or a default value of T - /// if the is an empty array of - /// or if the types of T aren't the , , , + /// A T converted from , or a default value of T + /// if is an empty array of + /// or if the type of T isn't , , , /// , , , , - /// , , . + /// , or . /// /// /// An array of to convert. /// /// - /// A that indicates the byte order of the . + /// A that indicates the byte order of . /// /// - /// The type of the return value. The T must be a value type. + /// The type of the return. The T must be a value type. /// /// - /// Is thrown when the parameter passed to a method is invalid because it is . + /// is . /// public static T To(this byte[] src, ByteOrder srcOrder) where T : struct @@ -1389,46 +1389,37 @@ namespace WebSocketSharp { if (src.Length == 0) return default(T); - var type = typeof(T); + var type = typeof(T); var buffer = src.ToHostOrder(srcOrder); - if (type == typeof(Boolean)) - return (T)(object)BitConverter.ToBoolean(buffer, 0); - - if (type == typeof(Char)) - return (T)(object)BitConverter.ToChar(buffer, 0); - - if (type == typeof(Double)) - return (T)(object)BitConverter.ToDouble(buffer, 0); - - if (type == typeof(Int16)) - return (T)(object)BitConverter.ToInt16(buffer, 0); - - if (type == typeof(Int32)) - return (T)(object)BitConverter.ToInt32(buffer, 0); - - if (type == typeof(Int64)) - return (T)(object)BitConverter.ToInt64(buffer, 0); - - if (type == typeof(Single)) - return (T)(object)BitConverter.ToSingle(buffer, 0); - - if (type == typeof(UInt16)) - return (T)(object)BitConverter.ToUInt16(buffer, 0); - - if (type == typeof(UInt32)) - return (T)(object)BitConverter.ToUInt32(buffer, 0); - if (type == typeof(UInt64)) - return (T)(object)BitConverter.ToUInt64(buffer, 0); - - return 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); } /// - /// Converts the specified data to an array of . + /// Converts the specified to an array of . /// /// - /// An array of converted from the . + /// An array of converted from . /// /// /// A T to convert. @@ -1437,59 +1428,37 @@ namespace WebSocketSharp { /// A that indicates the byte order of the return. /// /// - /// The type of the . The T must be a value type. + /// The type of . The T must be a value type. /// public static byte[] ToByteArray(this T value, ByteOrder order) where T : struct { var type = typeof(T); - byte[] buffer; - if (type == typeof(Boolean)) - { - buffer = BitConverter.GetBytes((Boolean)(object)value); - } - else if (type == typeof(Char)) - { - buffer = BitConverter.GetBytes((Char)(object)value); - } - else if (type == typeof(Double)) - { - buffer = BitConverter.GetBytes((Double)(object)value); - } - else if (type == typeof(Int16)) - { - buffer = BitConverter.GetBytes((Int16)(object)value); - } - else if (type == typeof(Int32)) - { - buffer = BitConverter.GetBytes((Int32)(object)value); - } - else if (type == typeof(Int64)) - { - buffer = BitConverter.GetBytes((Int64)(object)value); - } - else if (type == typeof(Single)) - { - buffer = BitConverter.GetBytes((Single)(object)value); - } - else if (type == typeof(UInt16)) - { - buffer = BitConverter.GetBytes((UInt16)(object)value); - } - else if (type == typeof(UInt32)) - { - buffer = BitConverter.GetBytes((UInt32)(object)value); - } - else if (type == typeof(UInt64)) - { - buffer = BitConverter.GetBytes((UInt64)(object)value); - } - else - { - buffer = new byte[]{}; - } - - return buffer.Length == 0 || order.IsHostOrder() + 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() ? buffer : buffer.Reverse().ToArray(); } @@ -1498,34 +1467,34 @@ namespace WebSocketSharp { /// Converts the order of the specified array of to the host byte order. /// /// - /// An array of converted from the . + /// An array of converted from . /// /// /// An array of to convert. /// /// - /// A that indicates the byte order of the . + /// A that indicates the byte order of . /// /// - /// Is thrown when the parameter passed to a method is invalid because it is . + /// is . /// public static byte[] ToHostOrder(this byte[] src, ByteOrder srcOrder) { if (src == null) throw new ArgumentNullException("src"); - return src.Length == 0 || srcOrder.IsHostOrder() + return src.Length <= 1 || srcOrder.IsHostOrder() ? src : src.Reverse().ToArray(); } /// - /// Converts the specified array to a concatenated the specified separator string - /// between each element of this array. + /// Converts the specified to a that concatenates + /// the each element of across the specified . /// /// - /// A converted from the parameter, or a - /// if the length of the is zero. + /// A converted from , or a + /// if the length of is zero. /// /// /// An array of T to convert. @@ -1534,10 +1503,10 @@ namespace WebSocketSharp { /// A that contains a separator string. /// /// - /// The type of elements in the . + /// The type of elements in . /// /// - /// Is thrown when the parameter passed to a method is invalid because it is . + /// is . /// public static string ToString(this T[] array, string separator) { @@ -1551,13 +1520,13 @@ namespace WebSocketSharp { if (separator == null) separator = String.Empty; - var sb = new StringBuilder(); + var buffer = new StringBuilder(64); (len - 1).Times(i => - sb.AppendFormat("{0}{1}", array[i].ToString(), separator) + buffer.AppendFormat("{0}{1}", array[i].ToString(), separator) ); - sb.Append(array[len - 1].ToString()); - return sb.ToString(); + buffer.Append(array[len - 1].ToString()); + return buffer.ToString(); } /// diff --git a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll index cd7ef85f..0f292a36 100755 Binary files a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll and b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll differ