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


C# Type.GetEnumNames方法代码示例

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


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

示例1: EnumSchema

 public EnumSchema(Type t, Model sModel)
 {
     Type = "string";
     Ref = DefintionsRefLocation + t.Name;
     Description = sModel.Description;
     Enum = t.GetEnumNames();
 }
开发者ID:khellang,项目名称:Nancy.Swagger,代码行数:7,代码来源:SwaggerSchemaFactory.cs

示例2: CreateSpecFor

        private ModelSpec CreateSpecFor(Type type, bool deferIfComplex, Dictionary<Type, ModelSpec> deferredMappings)
        {
            if (_customMappings.ContainsKey(type))
                return _customMappings[type];

            if (PrimitiveMappings.ContainsKey(type))
                return PrimitiveMappings[type];

            if (type.IsEnum)
                return new ModelSpec {Type = "string", Enum = type.GetEnumNames()};

            Type innerType;
            if (type.IsNullable(out innerType))
                return CreateSpecFor(innerType, deferIfComplex, deferredMappings);

            Type itemType;
            if (type.IsEnumerable(out itemType))
                return new ModelSpec { Type = "array", Items = CreateSpecFor(itemType, true, deferredMappings) };

            // Anthing else is complex

            if (deferIfComplex)
            {
                if (!deferredMappings.ContainsKey(type))
                    deferredMappings.Add(type, null);
                
                // Just return a reference for now
                return new ModelSpec {Ref = UniqueIdFor(type)};
            }

            return CreateComplexSpecFor(type, deferredMappings);
        }
开发者ID:robinvanderknaap,项目名称:Swashbuckle.Lite,代码行数:32,代码来源:ModelSpecGenerator.cs

示例3: EnumConfiguration

 public EnumConfiguration(Type enumType)
 {
     _signed = IsSignedEnum(enumType);
     _flags = IsFlagsEnum(enumType);
     _names = enumType.GetEnumNames();
     var members = enumType.GetMembers(BindingFlags.Static | BindingFlags.Public);
     Debug.Assert(members.Length == _names.Length);
     for (int i = 0; i < members.Length; i++)
     {
         var a = members[i].GetCustomAttributes<PersistedNameAttribute>().FirstOrDefault();
         if (a != null) _names[i] = a.Name;
     }
     var undertype = enumType.GetEnumUnderlyingType();
     var enumValues = enumType.GetEnumValues();
     IEnumerable<ulong> enumValuesUlongs;
     if (undertype == typeof(int)) enumValuesUlongs = enumValues.Cast<int>().Select(i => (ulong)i);
     else if (undertype == typeof(uint)) enumValuesUlongs = enumValues.Cast<uint>().Select(i => (ulong)i);
     else if (undertype == typeof(sbyte)) enumValuesUlongs = enumValues.Cast<sbyte>().Select(i => (ulong)i);
     else if (undertype == typeof(byte)) enumValuesUlongs = enumValues.Cast<byte>().Select(i => (ulong)i);
     else if (undertype == typeof(short)) enumValuesUlongs = enumValues.Cast<short>().Select(i => (ulong)i);
     else if (undertype == typeof(ushort)) enumValuesUlongs = enumValues.Cast<ushort>().Select(i => (ulong)i);
     else if (undertype == typeof(long)) enumValuesUlongs = enumValues.Cast<long>().Select(i => (ulong)i);
     else enumValuesUlongs = enumValues.Cast<ulong>();
     _values = enumValuesUlongs.ToArray();
 }
开发者ID:Xamarui,项目名称:BTDB,代码行数:25,代码来源:EnumFieldHandler.cs

示例4: ConvertTypeToDefinition

        private static Definition ConvertTypeToDefinition(Type definitionType, IList<string> hiddenTags,
                                                          Stack<Type> typesStack)
        {
            var schema = new DefinitionSchema
            {
                Name = definitionType.FullName
            };

            ProcessTypeAttributes(definitionType, schema);

            // process
            schema.TypeFormat = Helpers.MapSwaggerType(definitionType, null);
            if (schema.TypeFormat.Type == ParameterType.String && schema.TypeFormat.Format == "enum")
            {
                schema.Enum = new List<string>();
                List<string> listOfEnumNames = definitionType.GetEnumNames().ToList();
                foreach (string enumName in listOfEnumNames)
                {
                    schema.Enum.Add(GetEnumMemberValue(definitionType, enumName));
                }
            }
            else
            {
                ProcessProperties(definitionType, schema, hiddenTags, typesStack);
            }

            return new Definition
            {
                Schema = schema
            };
        }
开发者ID:Robin--,项目名称:swaggerwcf,代码行数:31,代码来源:DefinitionsBuilder.cs

示例5: TSConstEnumeration

 public TSConstEnumeration(Type enumType)
 {
     if (!enumType.IsEnum)
         throw new Exception("Must be an enum");
     _type = enumType;
     Name = enumType.Name;
     ModuleName = enumType.Namespace;
     EnumNames = enumType.GetEnumNames().ToList();
 }
开发者ID:KnowledgeLakegithub,项目名称:.NetTSGenerator,代码行数:9,代码来源:TSConstEnumeration.cs

示例6: GetSwaggerType

 public SwaggerType GetSwaggerType(Type type)
 {
     if (type.IsEnum)
     {
         return new SwaggerType
         {
             Type = "string",
             Enum = type.GetEnumNames().AsEnumerable()
         };
     }
     return null;
 }
开发者ID:Tom-Kennedy,项目名称:Swagger.Net,代码行数:12,代码来源:EnumTypeProvider.cs

示例7: EnumParse

 internal static object EnumParse(Type enumType, object obj)
 {
     object result;
     string objToString = obj.ToString().Trim();
     try
     {
         result = Enum.Parse(enumType, objToString, true);
     }
     catch (ArgumentException)
     {
         throw new ArgumentException($"'{objToString}' is not a value of enum '{enumType.Name}'. Legal values are: {string.Join(", ", enumType.GetEnumNames())}");
     }
     return result;
 }
开发者ID:Excel-DNA,项目名称:Registration,代码行数:14,代码来源:ParameterConversions.cs

示例8: EnumValueCollection

 internal EnumValueCollection(Type enumType)
 {
     if (enumType.IsEnum)
     {
         m_possibleValues = new List<EnumValue>();
         foreach (string val in enumType.GetEnumNames())
         {
             EnumValue newVal = new EnumValue();
             newVal.Value = val;
             m_possibleValues.Add(newVal);
         }
         m_currentValue = m_possibleValues[0];
         m_sourceEnum = enumType.GetTraceLabQualifiedName();
     }
 }
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:15,代码来源:EnumValueCollection.cs

示例9: EnumAllValues

 internal static string EnumAllValues(Type enumType)
 {
     string[] enumNames = enumType.GetEnumNames();
     string str = ", ";
     StringBuilder builder = new StringBuilder();
     if (enumNames.Length != 0)
     {
         for (int i = 0; i < enumNames.Length; i++)
         {
             builder.Append(enumNames[i]);
             builder.Append(str);
         }
         builder.Remove(builder.Length - str.Length, str.Length);
     }
     return builder.ToString();
 }
开发者ID:nickchal,项目名称:pash,代码行数:16,代码来源:EnumMinimumDisambiguation.cs

示例10: EnumDisambiguate

 internal static string EnumDisambiguate(string text, Type enumType)
 {
     string[] strArray2;
     string[] enumNames = enumType.GetEnumNames();
     CompareInfo.GetCompareInfo(CultureInfo.InvariantCulture.LCID);
     List<string> list = new List<string>();
     foreach (string str in enumNames)
     {
         if (str.StartsWith(text, StringComparison.OrdinalIgnoreCase))
         {
             list.Add(str);
         }
     }
     if (list.Count == 0)
     {
         throw InterpreterError.NewInterpreterException(null, typeof(RuntimeException), null, "NoEnumNameMatch", EnumExpressionEvaluatorStrings.NoEnumNameMatch, new object[] { text, EnumAllValues(enumType) });
     }
     if (list.Count == 1)
     {
         return list[0];
     }
     foreach (string str2 in list)
     {
         if (str2.Equals(text, StringComparison.OrdinalIgnoreCase))
         {
             return str2;
         }
     }
     if (specialDisambiguateCases.TryGetValue(enumType, out strArray2))
     {
         foreach (string str3 in strArray2)
         {
             if (str3.StartsWith(text, StringComparison.OrdinalIgnoreCase))
             {
                 return str3;
             }
         }
     }
     StringBuilder builder = new StringBuilder(list[0]);
     string str4 = ", ";
     for (int i = 1; i < list.Count; i++)
     {
         builder.Append(str4);
         builder.Append(list[i]);
     }
     throw InterpreterError.NewInterpreterException(null, typeof(RuntimeException), null, "MultipleEnumNameMatch", EnumExpressionEvaluatorStrings.MultipleEnumNameMatch, new object[] { text, builder.ToString() });
 }
开发者ID:nickchal,项目名称:pash,代码行数:47,代码来源:EnumMinimumDisambiguation.cs

示例11: EnumTypeDescriptor

 public EnumTypeDescriptor(ITypeDescriptorCallbacks typeSerializers, Type type)
 {
     _typeSerializers = typeSerializers;
     _type = type;
     _name = typeSerializers.TypeNameMapper.ToName(type);
     _signed = IsSignedEnum(type);
     _flags = IsFlagsEnum(type);
     var undertype = type.GetEnumUnderlyingType();
     var enumValues = type.GetEnumValues();
     IEnumerable<ulong> enumValuesUlongs;
     if (undertype == typeof(int)) enumValuesUlongs = enumValues.Cast<int>().Select(i => (ulong)i);
     else if (undertype == typeof(uint)) enumValuesUlongs = enumValues.Cast<uint>().Select(i => (ulong)i);
     else if (undertype == typeof(sbyte)) enumValuesUlongs = enumValues.Cast<sbyte>().Select(i => (ulong)i);
     else if (undertype == typeof(byte)) enumValuesUlongs = enumValues.Cast<byte>().Select(i => (ulong)i);
     else if (undertype == typeof(short)) enumValuesUlongs = enumValues.Cast<short>().Select(i => (ulong)i);
     else if (undertype == typeof(ushort)) enumValuesUlongs = enumValues.Cast<ushort>().Select(i => (ulong)i);
     else if (undertype == typeof(long)) enumValuesUlongs = enumValues.Cast<long>().Select(i => (ulong)i);
     else enumValuesUlongs = enumValues.Cast<ulong>();
     _pairs = type.GetEnumNames().Zip(enumValuesUlongs.ToArray(), (s, v) => new KeyValuePair<string, ulong>(s, v)).ToList();
 }
开发者ID:klesta490,项目名称:BTDB,代码行数:20,代码来源:EnumTypeDescriptor.cs

示例12: Initialize

        private void Initialize(Assembly assembly, string amsNetIdTarget, ushort amsPortTarget)
        {
            t_TcAdsClient = assembly.GetType("TwinCAT.Ads.TcAdsClient");
            t_AdsStream = assembly.GetType("TwinCAT.Ads.AdsStream");
            t_StateInfo = assembly.GetType("TwinCAT.Ads.StateInfo");
            t_DeviceInfo = assembly.GetType("TwinCAT.Ads.DeviceInfo");
            t_AdsVersion = assembly.GetType("TwinCAT.Ads.AdsVersion");
            t_AdsTransMode = assembly.GetType("TwinCAT.Ads.AdsTransMode");

            adsTransMode = Activator.CreateInstance(t_AdsTransMode);

            Array n = t_AdsTransMode.GetEnumNames();
            Array v = t_AdsTransMode.GetEnumValues();
            int c = n.Length;
            for (int i = 0; i < c; i++)
            {
                if ((string)n.GetValue(i) == "Cyclic")
                    AdsTransMode_Cyclic = v.GetValue(i);
                else
                    if ((string)n.GetValue(i) == "OnChange")
                        AdsTransMode_OnChange = v.GetValue(i);
            }

            client = Activator.CreateInstance(t_TcAdsClient);
            client.Connect(amsNetIdTarget, amsPortTarget);

            var this_eventHandler =
                typeof(AdsClient).GetMethod(
                    "TcAdsClient_AdsNotification",
                    BindingFlags.Instance | BindingFlags.NonPublic);

            client.AdsNotification +=
                (dynamic)Delegate.CreateDelegate(
                        t_TcAdsClient.GetEvent("AdsNotification").EventHandlerType,
                        this,
                        this_eventHandler);
        }
开发者ID:nikvoronin,项目名称:adsclient,代码行数:37,代码来源:AdsClient.cs

示例13: GetEnum

        private RamlType GetEnum(Type type)
        {
            var ramlType = new RamlType
            {
                Type = "string",
                Scalar = new Property { Enum = type.GetEnumNames() } // TODO: check!!
            };

            return ramlType;
        }
开发者ID:mulesoft-labs,项目名称:raml-dotnet-apiexplorer,代码行数:10,代码来源:Raml1TypeBuilder.cs

示例14: CreateDataType

        private DataType CreateDataType(Type type, bool deferIfComplex, IDictionary<Type, DataType> complexMappings)
        {
            if (_customMappings.ContainsKey(type))
                return _customMappings[type];

            if (StaticMappings.ContainsKey(type))
                return StaticMappings[type];

            if (type.IsEnum)
                return new DataType { Type = "string", Enum = type.GetEnumNames() };

            Type innerType;
            if (type.IsNullable(out innerType))
                return CreateDataType(innerType, deferIfComplex, complexMappings);

            Type itemType;
            if (type.IsEnumerable(out itemType))
                return new DataType { Type = "array", Items = CreateDataType(itemType, true, complexMappings) };

            // Anthing else is complex

            if (deferIfComplex)
            {
                if (!complexMappings.ContainsKey(type))
                    complexMappings.Add(type, null);

                // Just return a reference for now
                return new DataType { Ref = UniqueIdFor(type) };
            }

            return CreateComplexDataType(type, complexMappings);
        }
开发者ID:kevynb,项目名称:Swashbuckle,代码行数:32,代码来源:DataTypeGenerator.cs

示例15: CreateModelSpec

        private ModelSpec CreateModelSpec(Type type)
        {
            // Primitives, incl. enums
            if (_predefinedTypeMap.ContainsKey(type))
                return _predefinedTypeMap[type];

            if (type.IsEnum)
                return new ModelSpec
                    {
                        Type = "string",
                        Enum = type.GetEnumNames()
                    };

            Type enumerableTypeArgument;
            if (type.IsEnumerable(out enumerableTypeArgument))
                return CreateContainerSpec(enumerableTypeArgument);

            Type nullableTypeArgument;
            if (type.IsNullable(out nullableTypeArgument))
                return FindOrCreateFor(nullableTypeArgument);

            return CreateComplexSpec(type);
        }
开发者ID:nprovencher,项目名称:Swashbuckle,代码行数:23,代码来源:ModelSpecMap.cs


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