当前位置: 首页>>代码示例>>C#>>正文


C# Type.GetTypeCode方法代码示例

本文整理汇总了C#中Type.GetTypeCode方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetTypeCode方法的具体用法?C# Type.GetTypeCode怎么用?C# Type.GetTypeCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Type的用法示例。


在下文中一共展示了Type.GetTypeCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ToCode

 internal static InternalPrimitiveTypeE ToCode(Type type) =>
         type == null ? ToPrimitiveTypeEnum(TypeCode.Empty) :
         type.GetTypeInfo().IsPrimitive ? ToPrimitiveTypeEnum(type.GetTypeCode()) :
         ReferenceEquals(type, s_typeofDateTime) ? InternalPrimitiveTypeE.DateTime :
         ReferenceEquals(type, s_typeofTimeSpan) ? InternalPrimitiveTypeE.TimeSpan :
         ReferenceEquals(type, s_typeofDecimal) ? InternalPrimitiveTypeE.Decimal :
         InternalPrimitiveTypeE.Invalid;
开发者ID:Corillian,项目名称:corefx,代码行数:7,代码来源:Converter.cs

示例2: IsInteger

 public static bool IsInteger(Type type)
 {
     type = GetNonNullableType(type);
     if (type.GetTypeInfo().IsEnum)
     {
         return false;
     }
     switch (type.GetTypeCode())
     {
         case TypeCode.Byte:
         case TypeCode.SByte:
         case TypeCode.Int16:
         case TypeCode.Int32:
         case TypeCode.Int64:
         case TypeCode.UInt16:
         case TypeCode.UInt32:
         case TypeCode.UInt64:
             return true;
         default:
             return false;
     }
 }
开发者ID:rajeevkb,项目名称:corefx,代码行数:22,代码来源:TypeUtils.cs

示例3: IsNumeric

 public static bool IsNumeric(Type type)
 {
     type = GetNonNullableType(type);
     if (!type.GetTypeInfo().IsEnum)
     {
         switch (type.GetTypeCode())
         {
             case TypeCode.Char:
             case TypeCode.SByte:
             case TypeCode.Byte:
             case TypeCode.Int16:
             case TypeCode.Int32:
             case TypeCode.Int64:
             case TypeCode.Double:
             case TypeCode.Single:
             case TypeCode.UInt16:
             case TypeCode.UInt32:
             case TypeCode.UInt64:
                 return true;
         }
     }
     return false;
 }
开发者ID:rajeevkb,项目名称:corefx,代码行数:23,代码来源:TypeUtils.cs

示例4: GetArrayItemName

 private static string GetArrayItemName(Type type)
 {
     switch (type.GetTypeCode())
     {
         case TypeCode.Boolean:
             return "boolean";
         case TypeCode.DateTime:
             return "dateTime";
         case TypeCode.Decimal:
             return "decimal";
         case TypeCode.Int32:
             return "int";
         case TypeCode.Int64:
             return "long";
         case TypeCode.Single:
             return "float";
         case TypeCode.Double:
             return "double";
         default:
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxInvalidUseOfPrimitiveOperationFormatter));
     }
 }
开发者ID:shijiaxing,项目名称:wcf,代码行数:22,代码来源:PrimitiveOperationFormatter.cs

示例5: WriteAnyType

 internal void WriteAnyType(object value, Type valueType)
 {
     bool handled = true;
     switch (valueType.GetTypeCode())
     {
         case TypeCode.Boolean:
             WriteBoolean((bool)value);
             break;
         case TypeCode.Char:
             WriteChar((char)value);
             break;
         case TypeCode.Byte:
             WriteUnsignedByte((byte)value);
             break;
         case TypeCode.Int16:
             WriteShort((short)value);
             break;
         case TypeCode.Int32:
             WriteInt((int)value);
             break;
         case TypeCode.Int64:
             WriteLong((long)value);
             break;
         case TypeCode.Single:
             WriteFloat((float)value);
             break;
         case TypeCode.Double:
             WriteDouble((double)value);
             break;
         case TypeCode.Decimal:
             WriteDecimal((decimal)value);
             break;
         case TypeCode.DateTime:
             WriteDateTime((DateTime)value);
             break;
         case TypeCode.String:
             WriteString((string)value);
             break;
         case TypeCode.SByte:
             WriteSignedByte((sbyte)value);
             break;
         case TypeCode.UInt16:
             WriteUnsignedShort((ushort)value);
             break;
         case TypeCode.UInt32:
             WriteUnsignedInt((uint)value);
             break;
         case TypeCode.UInt64:
             WriteUnsignedLong((ulong)value);
             break;
         case TypeCode.Empty:
         case TypeCode.Object:
         default:
             if (valueType == Globals.TypeOfByteArray)
                 WriteBase64((byte[])value);
             else if (valueType == Globals.TypeOfObject)
             {
                 //Write Nothing
             }
             else if (valueType == Globals.TypeOfTimeSpan)
                 WriteTimeSpan((TimeSpan)value);
             else if (valueType == Globals.TypeOfGuid)
                 WriteGuid((Guid)value);
             else if (valueType == Globals.TypeOfUri)
                 WriteUri((Uri)value);
             else if (valueType == Globals.TypeOfXmlQualifiedName)
                 WriteQName((XmlQualifiedName)value);
             else
                 handled = false;
             break;
     }
     if (!handled)
         throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateInvalidPrimitiveTypeException(valueType));
 }
开发者ID:swaroop-sridhar,项目名称:corefx,代码行数:74,代码来源:XmlWriterDelegator.cs

示例6: CanOptimizeSwitchType

 // Determines if the type is an integer we can switch on.
 private static bool CanOptimizeSwitchType(Type valueType)
 {
     // enums & char are allowed
     switch (valueType.GetTypeCode())
     {
         case TypeCode.Byte:
         case TypeCode.SByte:
         case TypeCode.Char:
         case TypeCode.Int16:
         case TypeCode.Int32:
         case TypeCode.UInt16:
         case TypeCode.UInt32:
         case TypeCode.Int64:
         case TypeCode.UInt64:
             return true;
         default:
             return false;
     }
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:20,代码来源:LambdaCompiler.Statements.cs

示例7: SwitchInfo

 internal SwitchInfo(SwitchExpression node, LocalBuilder value, Label @default)
 {
     Node = node;
     Value = value;
     Default = @default;
     Type = Node.SwitchValue.Type;
     IsUnsigned = TypeUtils.IsUnsigned(Type);
     var code = Type.GetTypeCode();
     Is64BitSwitch = code == TypeCode.UInt64 || code == TypeCode.Int64;
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:10,代码来源:LambdaCompiler.Statements.cs

示例8: GetTypeNameHelper

 private string GetTypeNameHelper(Type type)
 {
     switch (type.GetTypeCode())
     {
         case TypeCode.Boolean:
             return "win:Boolean";
         case TypeCode.Byte:
             return "win:UInt8";
         case TypeCode.Char:
         case TypeCode.UInt16:
             return "win:UInt16";
         case TypeCode.UInt32:
             return "win:UInt32";
         case TypeCode.UInt64:
             return "win:UInt64";
         case TypeCode.SByte:
             return "win:Int8";
         case TypeCode.Int16:
             return "win:Int16";
         case TypeCode.Int32:
             return "win:Int32";
         case TypeCode.Int64:
             return "win:Int64";
         case TypeCode.String:
             return "win:UnicodeString";
         case TypeCode.Single:
             return "win:Float";
         case TypeCode.Double:
             return "win:Double";
         case TypeCode.DateTime:
             return "win:FILETIME";
         default:
             if (type == typeof(Guid))
                 return "win:GUID";
             else if (type == typeof(IntPtr))
                 return "win:Pointer";
             else if ((type.IsArray || type.IsPointer) && type.GetElementType() == typeof(byte))
                 return "win:Binary";
                 
             ManifestError(Resources.GetResourceString("EventSource_UnsupportedEventTypeInManifest", type.Name), true);
             return string.Empty;
     }
 }
开发者ID:kouvel,项目名称:coreclr,代码行数:43,代码来源:EventSource_CoreCLR.cs

示例9: IsUnsignedInt

 public static bool IsUnsignedInt(Type type)
 {
     type = GetNonNullableType(type);
     if (!type.GetTypeInfo().IsEnum)
     {
         switch (type.GetTypeCode())
         {
             case TypeCode.UInt16:
             case TypeCode.UInt32:
             case TypeCode.UInt64:
                 return true;
         }
     }
     return false;
 }
开发者ID:rajeevkb,项目名称:corefx,代码行数:15,代码来源:TypeUtils.cs

示例10: EmitConstantOne

 private void EmitConstantOne(Type type)
 {
     switch (type.GetTypeCode())
     {
         case TypeCode.UInt16:
         case TypeCode.UInt32:
         case TypeCode.Int16:
         case TypeCode.Int32:
             _ilg.Emit(OpCodes.Ldc_I4_1);
             break;
         case TypeCode.Int64:
         case TypeCode.UInt64:
             _ilg.Emit(OpCodes.Ldc_I8, (long)1);
             break;
         case TypeCode.Single:
             _ilg.Emit(OpCodes.Ldc_R4, 1.0f);
             break;
         case TypeCode.Double:
             _ilg.Emit(OpCodes.Ldc_R8, 1.0d);
             break;
         default:
             // we only have to worry about arithmetic types, see
             // TypeUtils.IsArithmetic
             throw ContractUtils.Unreachable;
     }
 }
开发者ID:dotnet,项目名称:corefx,代码行数:26,代码来源:LambdaCompiler.Unary.cs

示例11: EmitConvertArithmeticResult

        // Binary/unary operations on 8 and 16 bit operand types will leave a 
        // 32-bit value on the stack, because that's how IL works. For these
        // cases, we need to cast it back to the resultType, possibly using a
        // checked conversion if the original operator was convert
        private void EmitConvertArithmeticResult(ExpressionType op, Type resultType)
        {
            Debug.Assert(!resultType.IsNullableType());

            switch (resultType.GetTypeCode())
            {
                case TypeCode.Byte:
                    _ilg.Emit(IsChecked(op) ? OpCodes.Conv_Ovf_U1 : OpCodes.Conv_U1);
                    break;
                case TypeCode.SByte:
                    _ilg.Emit(IsChecked(op) ? OpCodes.Conv_Ovf_I1 : OpCodes.Conv_I1);
                    break;
                case TypeCode.UInt16:
                    _ilg.Emit(IsChecked(op) ? OpCodes.Conv_Ovf_U2 : OpCodes.Conv_U2);
                    break;
                case TypeCode.Int16:
                    _ilg.Emit(IsChecked(op) ? OpCodes.Conv_Ovf_I2 : OpCodes.Conv_I2);
                    break;
            }
        }
开发者ID:mesheets,项目名称:Theraot-CF,代码行数:24,代码来源:LambdaCompiler.Binary.net30.cs

示例12: IsFloatingPoint

 internal static bool IsFloatingPoint(Type type)
 {
     type = GetNonNullableType(type);
     switch (type.GetTypeCode())
     {
         case TypeCode.Single:
         case TypeCode.Double:
             return true;
         default:
             return false;
     }
 }
开发者ID:rajeevkb,项目名称:corefx,代码行数:12,代码来源:TypeUtils.cs

示例13: IsUnsigned

 internal static bool IsUnsigned(Type type)
 {
     type = GetNonNullableType(type);
     switch (type.GetTypeCode())
     {
         case TypeCode.Byte:
         case TypeCode.UInt16:
         case TypeCode.Char:
         case TypeCode.UInt32:
         case TypeCode.UInt64:
             return true;
         default:
             return false;
     }
 }
开发者ID:rajeevkb,项目名称:corefx,代码行数:15,代码来源:TypeUtils.cs

示例14: IsConvertible

 public static bool IsConvertible(Type type)
 {
     type = GetNonNullableType(type);
     if (type.GetTypeInfo().IsEnum)
     {
         return true;
     }
     switch (type.GetTypeCode())
     {
         case TypeCode.Boolean:
         case TypeCode.Byte:
         case TypeCode.SByte:
         case TypeCode.Int16:
         case TypeCode.Int32:
         case TypeCode.Int64:
         case TypeCode.UInt16:
         case TypeCode.UInt32:
         case TypeCode.UInt64:
         case TypeCode.Single:
         case TypeCode.Double:
         case TypeCode.Char:
             return true;
         default:
             return false;
     }
 }
开发者ID:rajeevkb,项目名称:corefx,代码行数:26,代码来源:TypeUtils.cs

示例15: IsIntegerOrBool

 public static bool IsIntegerOrBool(Type type)
 {
     type = GetNonNullableType(type);
     if (!type.GetTypeInfo().IsEnum)
     {
         switch (type.GetTypeCode())
         {
             case TypeCode.Int64:
             case TypeCode.Int32:
             case TypeCode.Int16:
             case TypeCode.UInt64:
             case TypeCode.UInt32:
             case TypeCode.UInt16:
             case TypeCode.Boolean:
             case TypeCode.SByte:
             case TypeCode.Byte:
                 return true;
         }
     }
     return false;
 }
开发者ID:rajeevkb,项目名称:corefx,代码行数:21,代码来源:TypeUtils.cs


注:本文中的Type.GetTypeCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。