--- trunk/RomCheater.Logging/Binary.cs 2014/04/15 14:52:10 812 +++ trunk/RomCheater.Logging/Binary.cs 2014/04/15 15:58:50 814 @@ -1,66 +1,66 @@ -//using System; -//using System.Collections.Generic; -//using System.Linq; -//using System.Text; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; -//namespace RomCheater.Logging -//{ -// public static class Binary where T : IConvertible -// { -// public static T ToValue(string binary) -// { -// /* NOTE: commented out types do not have a paramter for fromBase and cannot be converted to from binary or any other base*/ -// string type = (typeof(T).Name); -// object o = default(T); -// switch (type.ToLower()) -// { -// //case "boolean": // bool -// // o = Convert.ToBoolean(binary,2); -// // break; -// //case "string": // string -// // o = binary; -// // break; -// //case "char": // char -// // o = Convert.ToChar(binary,2); -// // break; -// case "byte": // unsigned byte -// o = Convert.ToByte(binary, 2); -// break; -// case "sbyte": // signed byte -// o = Convert.ToSByte(binary, 2); -// break; -// case "int16": // short -// o = Convert.ToInt16(binary,2); -// break; -// case "uint16": // ushort -// o = Convert.ToUInt16(binary, 2); -// break; -// case "int32": // int -// o = Convert.ToInt32(binary, 2); -// break; -// case "uint32": // uint -// o = Convert.ToUInt32(binary, 2); -// break; -// case "int64": // long -// o = Convert.ToInt64(binary, 2); -// break; -// case "uint64": // ulong -// o = Convert.ToUInt64(binary, 2); -// break; -// //case "single": // float -// // o = Convert.ToSingle(binary, 2); -// // break; -// //case "double": // double -// // o = Convert.ToDouble(binary, 2); -// // break; -// //case "decimal": // decimal -// // o = Convert.ToDecimal(binary, 2); -// // break; -// default: // object -// break; -// } +namespace RomCheater.Logging +{ + internal static class Binary where T : IConvertible + { + public static T ToValue(string binary) + { + /* NOTE: commented out types do not have a paramter for fromBase and cannot be converted to from binary or any other base*/ + string type = (typeof(T).Name); + object o = default(T); + switch (type.ToLower()) + { + //case "boolean": // bool + // o = Convert.ToBoolean(binary,2); + // break; + //case "string": // string + // o = binary; + // break; + //case "char": // char + // o = Convert.ToChar(binary,2); + // break; + case "byte": // unsigned byte + o = Convert.ToByte(binary, 2); + break; + case "sbyte": // signed byte + o = Convert.ToSByte(binary, 2); + break; + case "int16": // short + o = Convert.ToInt16(binary, 2); + break; + case "uint16": // ushort + o = Convert.ToUInt16(binary, 2); + break; + case "int32": // int + o = Convert.ToInt32(binary, 2); + break; + case "uint32": // uint + o = Convert.ToUInt32(binary, 2); + break; + case "int64": // long + o = Convert.ToInt64(binary, 2); + break; + case "uint64": // ulong + o = Convert.ToUInt64(binary, 2); + break; + //case "single": // float + // o = Convert.ToSingle(binary, 2); + // break; + //case "double": // double + // o = Convert.ToDouble(binary, 2); + // break; + //case "decimal": // decimal + // o = Convert.ToDecimal(binary, 2); + // break; + default: // object + break; + } -// return (T)Convert.ChangeType(o, typeof(T)); -// } -// } -//} + return (T)Convert.ChangeType(o, typeof(T)); + } + } +}