GetNames() private method

private GetNames ( Type enumType ) : String[]
enumType Type
return String[]
Exemplo n.º 1
0
        public MainWindow()
        {
            InitializeComponent();
            var carSize = Enum.GetNames(typeof(CarTypes));

            cboxCarType.ItemsSource = carSize;
        }
        public static List <IEnumValue> GetEnumValues(Type type)
        {
            if (type is null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (type.IsEnum)
            {
                List <IEnumValue> Values = new List <IEnumValue>();

                foreach (string Name in Enum.GetNames(type))
                {
                    Values.Add(
                        new EnumValue()
                    {
                        Value = Convert.ChangeType(
                            Enum.Parse(type, Name),
                            Enum.GetUnderlyingType(type)
                            ).ToString(),
                        Label = Name
                    });
                }

                return(Values);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 3
0
 //return the next to direct,when player in this position.
 public Action bestDirect()
 {
     if (rewards.All(x => x.Equals(rewards.First())))
     {
         return((Action)Random.Range(0, Enum.GetNames(typeof(Action)).Length));
     }
     return((Action)rewards.ToList().IndexOf(rewards.Max()));
 }
Exemplo n.º 4
0
 private static OpenApiSchema CreateEnumSchema(Type collectionType)
 {
     return(new OpenApiSchema
     {
         Type = "integer",
         Enum = Enum.GetNames(collectionType)
                .Select(e => new OpenApiInteger((int)Enum.Parse(collectionType, e)))
                .ToList <IOpenApiAny>(),
     });
 }
Exemplo n.º 5
0
        //============================================================
        // <T>获得枚举字符串行集合。</T>
        //
        // @param type 枚举对象
        // @return 名称
        //============================================================
        public static string ToStringLine(Type type)
        {
            string[] names  = SysEnum.GetNames(type);
            FString  result = new FString();
            int      count  = names.Length;

            for (int n = 0; n < count; n++)
            {
                if (n > 0)
                {
                    result.AppendLine();
                }
                result.Append(names[n]);
            }
            return(result.ToString());
        }
Exemplo n.º 6
0
        private void OptionsForm_Load(object sender, EventArgs e)
        {
            foreach (string language in Enum.GetNames(typeof(InterfaceLanguage)))
            {
                cmbUILanguage.Items.Add(language);
            }

            //Store Languages
            List <string> storeLanguages = new List <string>();

            foreach (string l in Enum.GetNames(typeof(StoreLanguage)))
            {
                string name;
                switch (l)
                {
                case "windows":
                    name = "Default";
                    break;

                case "zh_Hans":
                    name = CultureInfo.GetCultureInfo("zh-Hans").NativeName;
                    break;

                case "zh_Hant":
                    name = CultureInfo.GetCultureInfo("zh-Hant").NativeName;
                    break;

                case "pt_BR":
                    name = CultureInfo.GetCultureInfo("pt-BR").NativeName;
                    break;

                default:
                    name = CultureInfo.GetCultureInfo(l).NativeName;
                    break;
                }

                storeLanguages.Add(name);
            }

            cmbStoreLanguage.Items.AddRange(storeLanguages.ToArray());

            FillFieldsFromSettings();
        }
Exemplo n.º 7
0
        private static SchemaName GetSchema(IDictionary <string, OpenApiSchema> definitions, string swaggerDataType,
                                            Type propertyType, PropertyInfo property)
        {
            if (swaggerDataType == "object")
            {
                if (!TryGetMapFieldTypes(propertyType, out var mapTypes))
                {
                    return(new SchemaName
                    {
                        Name = ToCamelCase(property.Name),
                        Schema = new OpenApiSchema
                        {
                            Reference = BuildReference(definitions, propertyType)
                        }
                    });
                }

                return(new SchemaName
                {
                    Name = ToCamelCase(property.Name),
                    Schema = new OpenApiSchema
                    {
                        Type = swaggerDataType,
                        Properties = mapTypes
                                     .DistinctBy(t => t.Name)
                                     .ToDictionary(t => ToCamelCase(t.Name), t => new OpenApiSchema
                        {
                            Type = ToSwaggerDataType(t),
                            Reference = ToSwaggerDataType(t) == "object"
                                    ? BuildReference(definitions, t)
                                    : null
                        })
                    }
                });
            }

            OpenApiSchema items = null;

            if (swaggerDataType == "array")
            {
                var collectionType = GetCollectionType(propertyType);
                var dataType       = ToSwaggerDataType(collectionType);
                if (dataType == "object")
                {
                    items = new OpenApiSchema
                    {
                        Reference = BuildReference(definitions, collectionType)
                    };
                }
                else
                {
                    items = collectionType.GetTypeInfo().IsEnum
                        ? CreateEnumSchema(collectionType)
                        : new OpenApiSchema {
                        Type = ToSwaggerDataType(collectionType)
                    };
                }
            }

            return(new SchemaName
            {
                Name = ToCamelCase(property.Name),
                Schema = new OpenApiSchema
                {
                    Type = swaggerDataType,
                    Enum = propertyType.GetTypeInfo().IsEnum
                        ? Enum.GetNames(propertyType).Select(e => new OpenApiInteger((int)Enum.Parse(propertyType, e)))
                           .ToList <IOpenApiAny>()
                        : null,
                    Items = items,
                }
            });
        }
Exemplo n.º 8
0
 //============================================================
 // <T>获得枚举对象中值对应的名称。</T>
 //
 // @template T 枚举对象
 // @param value 值
 // @return 名称
 //============================================================
 public static string[] ToStringLines <T>()
 {
     return(SysEnum.GetNames(typeof(T)));
 }
Exemplo n.º 9
0
 //============================================================
 // <T>获得枚举字符串行集合。</T>
 //
 // @param type 枚举对象
 // @return 名称
 //============================================================
 public static string[] ToStringLines(Type type)
 {
     return(SysEnum.GetNames(type));
 }