當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。