本文整理汇总了C#中TypeCode.IsUnsigned方法的典型用法代码示例。如果您正苦于以下问题:C# TypeCode.IsUnsigned方法的具体用法?C# TypeCode.IsUnsigned怎么用?C# TypeCode.IsUnsigned使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeCode
的用法示例。
在下文中一共展示了TypeCode.IsUnsigned方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNumericConversion
private static Conversion GetNumericConversion(TypeCode inputTypeCode, TypeCode outputTypeCode)
{
Contract.Requires(inputTypeCode.IsNumeric() && inputTypeCode != TypeCode.Decimal);
Contract.Requires(outputTypeCode.IsNumeric() && outputTypeCode != TypeCode.Decimal);
Contract.Ensures(Contract.Result<Conversion>() != null);
bool fromUnsigned = inputTypeCode.IsUnsigned();
switch (outputTypeCode)
{
case TypeCode.Char:
if (inputTypeCode == TypeCode.Byte || inputTypeCode == TypeCode.UInt16)
{
return IdentityConversion.ExplicitNumeric;
}
return fromUnsigned ? NumericConversion.UInt16Un : NumericConversion.UInt16;
case TypeCode.SByte:
return fromUnsigned ? NumericConversion.SByteUn : NumericConversion.SByte;
case TypeCode.Byte:
return fromUnsigned ? NumericConversion.ByteUn : NumericConversion.Byte;
case TypeCode.Int16:
if (inputTypeCode == TypeCode.SByte || inputTypeCode == TypeCode.Byte)
{
return IdentityConversion.ImplicitNumeric;
}
return fromUnsigned ? NumericConversion.Int16Un : NumericConversion.Int16;
case TypeCode.UInt16:
if (inputTypeCode == TypeCode.Byte || inputTypeCode == TypeCode.Char)
{
return IdentityConversion.ImplicitNumeric;
}
return fromUnsigned ? NumericConversion.UInt16Un : NumericConversion.UInt16;
case TypeCode.Int32:
if (inputTypeCode < outputTypeCode || inputTypeCode == TypeCode.Char)
{
return IdentityConversion.ImplicitNumeric;
}
return fromUnsigned ? NumericConversion.Int32Un : NumericConversion.Int32;
case TypeCode.UInt32:
if (fromUnsigned)
{
if (inputTypeCode == TypeCode.UInt64)
{
return NumericConversion.UInt32Un;
}
return IdentityConversion.ImplicitNumeric;
}
return inputTypeCode < outputTypeCode ? NumericConversion.UInt32Empty : NumericConversion.UInt32;
case TypeCode.Int64:
if (inputTypeCode < outputTypeCode || inputTypeCode == TypeCode.Char)
{
return fromUnsigned ? NumericConversion.UInt64Implicit : NumericConversion.Int64Implicit;
}
return fromUnsigned ? NumericConversion.Int64UnExplicit : NumericConversion.Int64Explicit;
case TypeCode.UInt64:
if (fromUnsigned)
{
return NumericConversion.UInt64Implicit;
}
if (inputTypeCode < outputTypeCode)
{
return NumericConversion.UInt64Explicit;
}
return NumericConversion.UInt64UnExplicit;
case TypeCode.Single:
if (inputTypeCode == TypeCode.Double)
{
return NumericConversion.SingleExplicit;
}
if (inputTypeCode == TypeCode.UInt32 || inputTypeCode == TypeCode.UInt64)
{
return NumericConversion.SingleUnImplicit;
}
return NumericConversion.SingleImplicit;
case TypeCode.Double:
if (inputTypeCode == TypeCode.UInt32 || inputTypeCode == TypeCode.UInt64)
{
return NumericConversion.DoubleUn;
}
return NumericConversion.Double;
}
throw CommonExceptions.Unreachable();
}