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


C# Type.GetTypeCode方法代码示例

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


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

示例1: ToDbType

        public static DbType ToDbType(Type type)
        {
            DbType dbType;
            switch ( type.GetTypeCode() ) {
                case TypeCode.String:
                    dbType = DbType.String;
                    break;
                case TypeCode.Int32:
                    dbType = DbType.Int32;
                    break;
                case TypeCode.DateTime:
                    dbType = DbType.DateTime;
                    break;
                case TypeCode.Boolean:
                    dbType = DbType.Boolean;
                    break;
                default:
                    if(type == typeof(Guid))
                        dbType = DbType.Guid;
                    else
                        Enum.TryParse(type.GetTypeCode().ToString(), true, out dbType);
                    break;
            }

            return dbType;
        }
开发者ID:SmartFire,项目名称:yessql,代码行数:26,代码来源:SchemaUtils.cs

示例2: IsPrimitiveType

		/// <summary>
		/// Checks whether .NET type is primitive
		/// </summary>
		/// <param name="type">.NET type</param>
		/// <returns>Result of check (true - is primitive; false - is not primitive)</returns>
		public static bool IsPrimitiveType(Type type)
		{
			TypeCode typeCode = type.GetTypeCode();
			bool result = _primitiveTypeCodes.Contains(typeCode);

			return result;
		}
开发者ID:Taritsyn,项目名称:JavaScriptEngineSwitcher,代码行数:12,代码来源:ValidationHelpers.cs

示例3: IsNumeric

 // keep in sync with System.Core version
 internal static bool IsNumeric(Type type) {
     type = GetNonNullableType(type);
     if (!type.IsEnum()) {
         return IsNumeric(type.GetTypeCode());
     }
     return false;
 }
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:8,代码来源:TypeUtils.cs

示例4: FromDbValue

        public override object FromDbValue(Type fieldType, object value)
        {
            var strVal = value as string;
            if (strVal != null)
                return Enum.Parse(fieldType, strVal, ignoreCase:true);

            return Convert.ChangeType(value, fieldType.GetTypeCode());
        }
开发者ID:wbSD,项目名称:ServiceStack.OrmLite,代码行数:8,代码来源:SpecialConverters.cs

示例5: IsFloatingPoint

        /// <summary>
        /// Checks whether the given type is any kind of a floating point or not.
        /// </summary>
        /// <param name="Type">A type.</param>
        /// <returns>True if the type is any kind of a floating point; False otherwise.</returns>
        public static Boolean IsFloatingPoint(Type Type)
        {
            switch (Type.GetTypeCode(Type))
            {
                case TypeCode.Single:
                case TypeCode.Double:
                    return true;
            }

            return false;
        }
开发者ID:subbuballa,项目名称:Illias,代码行数:16,代码来源:NumericTypeExtensions.cs

示例6: ToQuotedString

        public override string ToQuotedString(Type fieldType, object value)
        {
            var typeCode = fieldType.GetTypeCode();
            switch (typeCode)
            {
                case TypeCode.Single:
                    return ((float)value).ToString(CultureInfo.InvariantCulture);
                case TypeCode.Double:
                    return ((double)value).ToString(CultureInfo.InvariantCulture);
                case TypeCode.Decimal:
                    return ((decimal)value).ToString(CultureInfo.InvariantCulture);
            }

            return base.ToQuotedString(fieldType, value);
        }
开发者ID:chrisklepeis,项目名称:ServiceStack.OrmLite,代码行数:15,代码来源:FloatConverters.cs

示例7: Create

        public static Instruction Create(Type type)
        {
            Debug.Assert(!type.IsEnum());
            switch (type.GetTypeCode()) {
                case TypeCode.Int16: return _Int16 ?? (_Int16 = new DivInt16());
                case TypeCode.Int32: return _Int32 ?? (_Int32 = new DivInt32());
                case TypeCode.Int64: return _Int64 ?? (_Int64 = new DivInt64());
                case TypeCode.UInt16: return _UInt16 ?? (_UInt16 = new DivUInt16());
                case TypeCode.UInt32: return _UInt32 ?? (_UInt32 = new DivUInt32());
                case TypeCode.UInt64: return _UInt64 ?? (_UInt64 = new DivUInt64());
                case TypeCode.Single: return _Single ?? (_Single = new DivSingle());
                case TypeCode.Double: return _Double ?? (_Double = new DivDouble());

                default:
                    throw Assert.Unreachable;
            }
        }
开发者ID:TerabyteX,项目名称:main,代码行数:17,代码来源:DivInstruction.cs

示例8: IsArithmetic

 // keep in sync with System.Core version
 internal static bool IsArithmetic(Type type) {
     type = GetNonNullableType(type);
     if (!type.IsEnum()) {
         switch (type.GetTypeCode()) {
             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:KonajuGames,项目名称:SharpLang,代码行数:18,代码来源:TypeUtils.cs

示例9: TypeInfo

        public TypeInfo(Type type)
        {
            Type = type;

            _members = Type
                // do not consider consts and static members.
                .GetFields(BindingFlags.Instance | BindingFlags.Public)
                .Select(makeMemberInfo)
                .ToArray();

            var defaultConstructor = Type.GetConstructor(new Type[] {});

            _constructor = defaultConstructor == null
                ? (Func<object>) (() => FormatterServices.GetUninitializedObject(Type))
                : (() => defaultConstructor.Invoke(null));

            IsObject = Type.GetTypeCode(type) == TypeCode.Object;
        }
开发者ID:pragmatrix,项目名称:Faser,代码行数:18,代码来源:TypeInfo.cs

示例10: Create

        public static Instruction Create(Type type)
        {
            Debug.Assert(!type.IsEnum());
            switch (type.GetTypeCode()) {
                case TypeCode.SByte: return _SByte ?? (_SByte = new LessThanSByte());
                case TypeCode.Byte: return _Byte ?? (_Byte = new LessThanByte());
                case TypeCode.Char: return _Char ?? (_Char = new LessThanChar());
                case TypeCode.Int16: return _Int16 ?? (_Int16 = new LessThanInt16());
                case TypeCode.Int32: return _Int32 ?? (_Int32 = new LessThanInt32());
                case TypeCode.Int64: return _Int64 ?? (_Int64 = new LessThanInt64());
                case TypeCode.UInt16: return _UInt16 ?? (_UInt16 = new LessThanUInt16());
                case TypeCode.UInt32: return _UInt32 ?? (_UInt32 = new LessThanUInt32());
                case TypeCode.UInt64: return _UInt64 ?? (_UInt64 = new LessThanUInt64());
                case TypeCode.Single: return _Single ?? (_Single = new LessThanSingle());
                case TypeCode.Double: return _Double ?? (_Double = new LessThanDouble());

                default:
                    throw Assert.Unreachable;
            }
        }
开发者ID:TerabyteX,项目名称:main,代码行数:20,代码来源:LessThanInstruction.cs

示例11: IsNumericType

        /// <summary>
        /// Gets a value indicating whether the specified type is one of the numeric types
        /// </summary>
        /// <param name="type">The type</param>
        /// <returns>true if the specified type is one of the numeric types; otherwise, false</returns>
        public static bool IsNumericType(Type type)
        {
            TypeCode typeCode = type.GetTypeCode();

            switch (typeCode)
            {
                case TypeCode.SByte:
                case TypeCode.Byte:
                case TypeCode.Int16:
                case TypeCode.UInt16:
                case TypeCode.Int32:
                case TypeCode.UInt32:
                case TypeCode.Int64:
                case TypeCode.UInt64:
                case TypeCode.Single:
                case TypeCode.Double:
                case TypeCode.Decimal:
                    return true;
                default:
                    return false;
            }
        }
开发者ID:Taritsyn,项目名称:MsieJavaScriptEngine,代码行数:27,代码来源:NumericHelpers.cs

示例12: ToDbValue

        public override object ToDbValue(Type fieldType, object value)
        {
            var isEnumFlags = fieldType.IsEnumFlags() ||
                (!fieldType.IsEnum && fieldType.IsNumericType()); //i.e. is real int && not Enum

            if (isEnumFlags && value.GetType().IsEnum)
                return Convert.ChangeType(value, fieldType.GetTypeCode());

            long enumValue;
            if (long.TryParse(value.ToString(), out enumValue))
            {
                if (isEnumFlags)
                    return enumValue;

                value = Enum.ToObject(fieldType, enumValue);
            }

            var enumString = DialectProvider.StringSerializer.SerializeToString(value);
            return enumString != null && enumString != "null"
                ? enumString.Trim('"') 
                : value.ToString();
        }
开发者ID:wrx362114,项目名称:ServiceStack.OrmLite,代码行数:22,代码来源:SpecialConverters.cs

示例13: Ldobj

 internal void Ldobj(Type type)
 {
     OpCode opCode = GetLdindOpCode(type.GetTypeCode());
     if (!opCode.Equals(OpCodes.Nop))
     {
         if (_codeGenTrace != CodeGenTrace.None)
             EmitSourceInstruction(opCode.ToString());
         _ilGen.Emit(opCode);
     }
     else
     {
         if (_codeGenTrace != CodeGenTrace.None)
             EmitSourceInstruction("Ldobj " + type);
         _ilGen.Emit(OpCodes.Ldobj, type);
     }
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:16,代码来源:CodeGenerator.cs

示例14: InternalConvert

 private void InternalConvert(Type source, Type target, bool isAddress)
 {
     if (target == source)
         return;
     if (target.GetTypeInfo().IsValueType)
     {
         if (source.GetTypeInfo().IsValueType)
         {
             OpCode opCode = GetConvOpCode(target.GetTypeCode());
             if (opCode.Equals(OpCodes.Nop))
                 throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.NoConversionPossibleTo, DataContract.GetClrTypeFullName(target))));
             else
             {
                 if (_codeGenTrace != CodeGenTrace.None)
                     EmitSourceInstruction(opCode.ToString());
                 _ilGen.Emit(opCode);
             }
         }
         else if (source.IsAssignableFrom(target))
         {
             Unbox(target);
             if (!isAddress)
                 Ldobj(target);
         }
         else
             throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.IsNotAssignableFrom, DataContract.GetClrTypeFullName(target), DataContract.GetClrTypeFullName(source))));
     }
     else if (target.IsAssignableFrom(source))
     {
         if (source.GetTypeInfo().IsValueType)
         {
             if (isAddress)
                 Ldobj(source);
             Box(source);
         }
     }
     else if (source.IsAssignableFrom(target))
     {
         Castclass(target);
     }
     else if (target.GetTypeInfo().IsInterface || source.GetTypeInfo().IsInterface)
     {
         Castclass(target);
     }
     else
         throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.IsNotAssignableFrom, DataContract.GetClrTypeFullName(target), DataContract.GetClrTypeFullName(source))));
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:47,代码来源:CodeGenerator.cs

示例15: LoadDefaultValue

 internal void LoadDefaultValue(Type type)
 {
     if (type.GetTypeInfo().IsValueType)
     {
         switch (type.GetTypeCode())
         {
             case TypeCode.Boolean:
                 Ldc(false);
                 break;
             case TypeCode.Char:
             case TypeCode.SByte:
             case TypeCode.Byte:
             case TypeCode.Int16:
             case TypeCode.UInt16:
             case TypeCode.Int32:
             case TypeCode.UInt32:
                 Ldc(0);
                 break;
             case TypeCode.Int64:
             case TypeCode.UInt64:
                 Ldc(0L);
                 break;
             case TypeCode.Single:
                 Ldc(0.0F);
                 break;
             case TypeCode.Double:
                 Ldc(0.0);
                 break;
             case TypeCode.Decimal:
             case TypeCode.DateTime:
             default:
                 LocalBuilder zero = DeclareLocal(type, "zero");
                 LoadAddress(zero);
                 InitObj(type);
                 Load(zero);
                 break;
         }
     }
     else
         Load(null);
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:41,代码来源:CodeGenerator.cs


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