public static SqlByte ConvertToSqlByte(object value)
{
Debug.Assert(value != null, "null argument in ConvertToSqlByte");
if ((value == DBNull.Value))
{ // null is not valid, SqlByte is struct
return SqlByte.Null;
}
Type valueType = value.GetType();
StorageType stype = DataStorage.GetStorageType(valueType);
switch (stype)
{
case StorageType.SqlByte:
return (SqlByte)value;
case StorageType.Byte:
return (byte)value;
default:
throw ExceptionBuilder.ConvertFailed(valueType, typeof(SqlByte));
}
}