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


C# Type.IsEnum方法代码示例

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


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

示例1: ArgumentTypeIsEnum

        public static void ArgumentTypeIsEnum(Type enumType, string parameterName)
        {
            ArgumentNotNull(enumType, "enumType");

            if (!enumType.IsEnum())
                throw new ArgumentException("Type {0} is not an Enum.".FormatWith(CultureInfo.InvariantCulture, enumType), parameterName);
        }
开发者ID:NetUtil,项目名称:Util,代码行数:7,代码来源:ValidationUtils.cs

示例2: Create

        public static Instruction Create(Type type)
        {
            // Boxed enums can be unboxed as their underlying types:
            switch ((type.IsEnum() ? Enum.GetUnderlyingType(type) : type).GetTypeCode()) {
                case TypeCode.Boolean: return _Boolean ?? (_Boolean = new NotEqualBoolean());
                case TypeCode.SByte: return _SByte ?? (_SByte = new NotEqualSByte());
                case TypeCode.Byte: return _Byte ?? (_Byte = new NotEqualByte());
                case TypeCode.Char: return _Char ?? (_Char = new NotEqualChar());
                case TypeCode.Int16: return _Int16 ?? (_Int16 = new NotEqualInt16());
                case TypeCode.Int32: return _Int32 ?? (_Int32 = new NotEqualInt32());
                case TypeCode.Int64: return _Int64 ?? (_Int64 = new NotEqualInt64());

                case TypeCode.UInt16: return _UInt16 ?? (_UInt16 = new NotEqualInt16());
                case TypeCode.UInt32: return _UInt32 ?? (_UInt32 = new NotEqualInt32());
                case TypeCode.UInt64: return _UInt64 ?? (_UInt64 = new NotEqualInt64());

                case TypeCode.Single: return _Single ?? (_Single = new NotEqualSingle());
                case TypeCode.Double: return _Double ?? (_Double = new NotEqualDouble());

                case TypeCode.Object:
                    if (!type.IsValueType()) {
                        return _Reference ?? (_Reference = new NotEqualReference());
                    }
                    // TODO: Nullable<T>
                    throw new NotImplementedException();

                default:
                    throw new NotImplementedException();
            }
        }
开发者ID:TerabyteX,项目名称:main,代码行数:30,代码来源:NotEqualInstruction.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: read

        private object read(Type nativeType)
        {
            object primitiveValue = _current.GetPrimitiveValue();
            
            if (nativeType.IsEnum() && primitiveValue.GetType() == typeof(string))
            {
                var enumMapping = _inspector.FindEnumMappingByType(nativeType);

                if (enumMapping != null)
                {
                    var enumLiteral = (string)primitiveValue;
                    if (enumMapping.ContainsLiteral(enumLiteral))
                        return enumMapping.ParseLiteral((string)primitiveValue);
                    else
                        throw Error.Format("Literal {0} is not a valid value for enumeration {1}", _current, enumLiteral, enumMapping.Name);
                }
                else
                    throw Error.Format("Cannot find an enumeration mapping for enum " + nativeType.Name, _current);
            }

            try
            {
                return PrimitiveTypeConverter.ConvertTo(primitiveValue, nativeType);
            }
            catch (NotSupportedException exc)
            {
                // thrown when an unsupported conversion was required
                throw Error.Format(exc.Message, _current);
            }
        }
开发者ID:alexandru360,项目名称:fhir-net-api,代码行数:30,代码来源:PrimitiveValueReader.cs

示例5: AddModelType

 public static void AddModelType(Type type)
 {
     if (type.IsEnum())
         Inspector.ImportEnum(type);
     else
         Inspector.ImportType(type);
 }
开发者ID:ranjancse26,项目名称:fhir-net-api,代码行数:7,代码来源:SerializationConfig.cs

示例6: Create

        public static EnumMapping Create(Type enumType)
        {
            if (enumType == null) throw Error.ArgumentNull("enumType");
            if (!enumType.IsEnum()) throw Error.Argument("enumType", "Type {0} is not an enumerated type", enumType.Name);

            var result = new EnumMapping();

            result.Name = getEnumName(enumType);
            result.EnumType = enumType;
            result._enumToLiteral = new Dictionary<Enum, string>();
            result._literalToEnum = new Dictionary<string, Enum>();

            foreach(var enumValue in ReflectionHelper.FindEnumFields(enumType))
            {
                var attr = ReflectionHelper.GetAttribute<EnumLiteralAttribute>(enumValue);

                string literal = enumValue.Name;
                if (attr != null) literal = attr.Literal;

                Enum value = (Enum)enumValue.GetValue(null);

                result._enumToLiteral.Add(value, literal);
                result._literalToEnum.Add(literal, value);
            }

            return result;
        }
开发者ID:rootdeveloper,项目名称:fhir-svn,代码行数:27,代码来源:EnumMapping.cs

示例7: ExtractObject

            public override object ExtractObject(Type requestedType)
            {
                if (requestedType == null)
                    return m_value;

                if (requestedType.IsEnum())
                    return ConvertEnum(requestedType, m_value);

                object v = Convert.ChangeType(m_value, requestedType);
                return v;
            }
开发者ID:GAIPS-INESC-ID,项目名称:FAtiMA-Toolkit,代码行数:11,代码来源:PrimitiveGraphNode.cs

示例8: GetEnumerationType

        public static Type GetEnumerationType(Type enumType)
        {
            if (enumType.IsNullableType())
            {
                enumType = enumType.GetTypeInfo().GenericTypeArguments[0];
            }

            if (!enumType.IsEnum())
                return null;

            return enumType;
        }
开发者ID:tamirdresher,项目名称:AutoMapper,代码行数:12,代码来源:TypeHelper.cs

示例9: GetTypeCode

        public static TypeCode GetTypeCode(Type type)
        {
            if (type == null) return TypeCode.Empty;
            TypeCode result;
            if (typeCodeLookup.TryGetValue(type, out result)) return result;

            if (type.IsEnum())
            {
                type = Enum.GetUnderlyingType(type);
                if (typeCodeLookup.TryGetValue(type, out result)) return result;
            }
            return TypeCode.Object;
        }
开发者ID:kuacci,项目名称:dapper-dot-net,代码行数:13,代码来源:TypeExtensions.cs

示例10: Create

        public static Instruction Create(Type type) {
            Debug.Assert(!type.IsEnum());
            switch (type.GetTypeCode()) {
                case TypeCode.Int16: return _Int16 ?? (_Int16 = new AddInt16());
                case TypeCode.Int32: return _Int32 ?? (_Int32 = new AddInt32());
                case TypeCode.Int64: return _Int64 ?? (_Int64 = new AddInt64());
                case TypeCode.UInt16: return _UInt16 ?? (_UInt16 = new AddUInt16());
                case TypeCode.UInt32: return _UInt32 ?? (_UInt32 = new AddUInt32());
                case TypeCode.UInt64: return _UInt64 ?? (_UInt64 = new AddUInt64());
                case TypeCode.Single: return _Single ?? (_Single = new AddSingle());
                case TypeCode.Double: return _Double ?? (_Double = new AddDouble());

                default:
                    throw Assert.Unreachable;
            }
        }
开发者ID:nlhepler,项目名称:mono,代码行数:16,代码来源:AddInstruction.cs

示例11: 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

示例12: GetNonGenericEnumInfo

        internal static NonGenericEnumInfo GetNonGenericEnumInfo(Type enumType)
        {
            Preconditions.NotNull(enumType, nameof(enumType));

            var nonGenericEnumInfos = _nonGenericEnumInfos;
            NonGenericEnumInfo info;
            if (!nonGenericEnumInfos.TryGetValue(enumType, out info))
            {
                if (enumType.IsEnum())
                {
                    var closedEnumsType = typeof(Enums<>).MakeGenericType(enumType);
                    info = new NonGenericEnumInfo((IEnumInfo)closedEnumsType.
#if TYPE_REFLECTION
                        GetField("Info", BindingFlags.Static | BindingFlags.Public)
#else
                        GetTypeInfo().GetDeclaredField("Info")
#endif
                    .GetValue(null), false);
                }
                else
                {
                    var nonNullableEnumType = Nullable.GetUnderlyingType(enumType);
                    if (nonNullableEnumType?.IsEnum() != true)
                    {
                        throw new ArgumentException("must be an enum type", nameof(enumType));
                    }
                    info = new NonGenericEnumInfo(GetInfo(nonNullableEnumType), true);
                }
                Dictionary<Type, NonGenericEnumInfo> oldNonGenericEnumInfos;
                do
                {
                    NonGenericEnumInfo foundInfo;
                    if (nonGenericEnumInfos.TryGetValue(enumType, out foundInfo))
                    {
                        return foundInfo;
                    }
                    oldNonGenericEnumInfos = nonGenericEnumInfos;
                    nonGenericEnumInfos = new Dictionary<Type, NonGenericEnumInfo>(nonGenericEnumInfos);
                    nonGenericEnumInfos.Add(enumType, info);
                } while ((nonGenericEnumInfos = Interlocked.CompareExchange(ref _nonGenericEnumInfos, nonGenericEnumInfos, oldNonGenericEnumInfos)) != oldNonGenericEnumInfos);
            }
            return info;
        }
开发者ID:TylerBrinkley,项目名称:Enums.NET,代码行数:43,代码来源:NonGenericEnums.cs

示例13: 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

示例14: ToQuotedString

        public override string ToQuotedString(Type fieldType, object value)
        {
            var isEnumAsInt = fieldType.HasAttribute<EnumAsIntAttribute>();
            if (isEnumAsInt)
                return this.ConvertNumber(Enum.GetUnderlyingType(fieldType), value).ToString();

            var isEnumFlags = fieldType.IsEnumFlags() ||
                (!fieldType.IsEnum() && fieldType.IsNumericType()); //i.e. is real int && not Enum

            long enumValue;
            if (!isEnumFlags && long.TryParse(value.ToString(), out enumValue))
                value = Enum.ToObject(fieldType, enumValue);

            var enumString = DialectProvider.StringSerializer.SerializeToString(value);
            if (enumString == null || enumString == "null")
                enumString = value.ToString();

            return !isEnumFlags 
                ? DialectProvider.GetQuotedValue(enumString.Trim('"')) 
                : enumString;
        }
开发者ID:ServiceStack,项目名称:ServiceStack.OrmLite,代码行数:21,代码来源:SpecialConverters.cs

示例15: read

        private object read(Type nativeType)
        {
            object primitiveValue = _current.GetPrimitiveValue();
            
            if (nativeType.IsEnum() && primitiveValue.GetType() == typeof(string))
            {
                var enumMapping = _inspector.FindEnumMappingByType(nativeType);

                if (enumMapping != null)
                    return enumMapping.ParseLiteral((string)primitiveValue);
            }

            try
            {
                return PrimitiveTypeConverter.Convert(primitiveValue, nativeType);
            }
            catch (NotSupportedException exc)
            {
                // thrown when an unsupported conversion was required
                throw Error.Format(exc.Message, _current);
            }
        }
开发者ID:ranjancse26,项目名称:fhir-net-api,代码行数:22,代码来源:PrimitiveValueReader.cs


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