private static String InternalFormattedHexString(object value)
{
TypeCode typeCode = Convert.GetTypeCode(value);
switch (typeCode)
{
case TypeCode.SByte:
return(((byte)(sbyte)value).ToString("X2", null));
case TypeCode.Byte:
return(((byte)value).ToString("X2", null));
case TypeCode.Boolean:
// direct cast from bool to byte is not allowed
return(Convert.ToByte((bool)value).ToString("X2", null));
case TypeCode.Int16:
return(((UInt16)(Int16)value).ToString("X4", null));
case TypeCode.UInt16:
return(((UInt16)value).ToString("X4", null));
case TypeCode.Char:
return(((UInt16)(Char)value).ToString("X4", null));
case TypeCode.UInt32:
return(((UInt32)value).ToString("X8", null));
case TypeCode.Int32:
return(((UInt32)(Int32)value).ToString("X8", null));
case TypeCode.UInt64:
return(((UInt64)value).ToString("X16", null));
case TypeCode.Int64:
return(((UInt64)(Int64)value).ToString("X16", null));
// All unsigned types will be directly cast
default:
throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_UnknownEnumType"));
}
}