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(); }
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 }; }
public EnumSchema(Type t, Model sModel) { Type = "string"; Ref = DefintionsRefLocation + t.Name; Description = sModel.Description; Enum = t.GetEnumNames(); }
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(); }
public static string[] GetNames(Type enumType) { if (enumType == null) { throw new ArgumentNullException(nameof(enumType)); } return(enumType.GetEnumNames()); }
public static String[] GetNames(Type enumType) { if (enumType == null) { throw new ArgumentNullException("enumType"); } Contract.Ensures(Contract.Result <String[]>() != null); Contract.EndContractBlock(); return(enumType.GetEnumNames()); }
public SwaggerType GetSwaggerType(Type type) { if (type.IsEnum) { return new SwaggerType { Type = "string", Enum = type.GetEnumNames().AsEnumerable() }; } return null; }
static void TestCodec() { AV.avcodec_register_all(); System.Type type = typeof(AV.AVCodecID); foreach (string name in type.GetEnumNames()) { AV.AVCodecID v = (AV.AVCodecID)Enum.Parse(type, name); IntPtr codec = AV.avcodec_find_decoder(v); string enabled = (codec == IntPtr.Zero) ? "disable" : "enable"; Console.WriteLine("{0}: {1}", name, enabled); } }
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; }
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(); } }
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(); }
public static int ParseEnum(Type type, string tag) { int value; if (int.TryParse(tag, out value)) { return(value); } var index = type.GetEnumNames().ToList().IndexOf(tag); if (index > -1) { return((int)type.GetEnumValues().GetValue(index)); } throw new Exception("Enum not found: " + tag); }
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() }); }
static public ValueDropdownList <T> Create_Enum_ValueDropdownList <T>() { ValueDropdownList <T> pListReturn = new ValueDropdownList <T>(); System.Type pEnumType = typeof(T); if (pEnumType.IsEnum) { string[] arrEnums = pEnumType.GetEnumNames(); for (int i = 0; i < arrEnums.Length; i++) { string strCurrentEnumName = arrEnums[i]; pListReturn.Add(strCurrentEnumName, (T)System.Enum.Parse(typeof(T), strCurrentEnumName)); } } return(pListReturn); }
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(); }
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); }
/// <summary> /// A virtual method to analyze an object and figure out the /// default settings for it. The attribute can't find the thing /// its attached to on its own, so this can't be done in a /// constructor, we have to do it for it. /// </summary> /// <param name="obj">The object to InferProperties</param> /// public override void InferProperties(Type obj) { base.InferProperties(obj); if (obj.IsEnum) { this.Properties.Add(new MappedPropertyAttribute { IncludeInPrimaryKey = true, Name = "Value", SqlType = "int" }); this.Properties.Add(new MappedPropertyAttribute { Name = "Description", SqlType = "nvarchar(max)" }); var names = obj.GetEnumNames(); foreach (var name in names) EnumValues.Add((int)Enum.Parse(obj, name), name); } else { this.Methods.AddRange( obj.GetMethods(PATTERN) .Select(this.GetMethodDescriptions) .Where(m => m != null)); this.Properties.AddRange( obj.GetProperties(PATTERN) .Select(this.GetPropertyDescriptions)); } }
// Types that have exlplicit declarations static TypeScriptType MakeEnum(Type type) { var name = type.Name; var declaration = "enum " + name + " {"; var count = 0; type.GetEnumNames().ToList().ForEach(n => { var sep = (count != 0 ? ", " : "") + "\n "; count++; declaration += sep + n; }); declaration += "\n}"; return new TypeScriptType { Name = name, Declaration = declaration }; }
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); }
private List<MemsInfo> GetTypeMembers(Type type,bool isStatic) { if (!typeMembers.ContainsKey(type)) { List<MemsInfo> tmp = new List<MemsInfo>(); if (type.IsEnum) { foreach (var item in type.GetEnumNames()) { tmp.Add(new MemsInfo(item, type.Name + "." + item, "Is Enum")); } } else if (type.IsClass) { if (isStatic) { foreach (var item in (from p in type.GetMethods() where p.IsStatic && p.IsPublic select p)) { if (item.Name.IndexOf("get_") == 0 || item.Name.IndexOf("set_") == 0 || item.Name.IndexOf("add_") == 0 || item.Name.IndexOf("remove_") == 0) { continue; } else { MemsInfo x = null; if ((x = tmp.Find(p => p.Name == item.Name)) != null) { x.type += "\r\n" + item.ToString(); } else { MemsInfo method = new MemsInfo(item.Name, item.ToString(), "Is Method"); tmp.Add(method); } } } } foreach (var item in (from p in type.GetProperties() select p)) { if (tmp.Find(p => p.Name == item.Name) == null) tmp.Add(new MemsInfo(item.Name, item.ToString(), "Is Properties")); } foreach (var item in (from p in type.GetEvents() select p)) { if (tmp.Find(p => p.Name == item.Name) == null) tmp.Add(new MemsInfo(item.Name, item.EventHandlerType.ToString()+"\r\n:Add(fuction(...){})+\r\n" + GetGetMethodstr(item.EventHandlerType), "Is Events")); } foreach (var item in (from p in type.GetFields() where p.IsStatic==isStatic && p.IsPublic select p)) { if (tmp.Find(p => p.Name == item.Name) == null) tmp.Add(new MemsInfo(item.Name, item.ToString(), "Is Field")); } if (type.BaseType != null) GetTypeMembers(tmp, type.BaseType, isStatic); } tmp.Sort((a, b) => a.Name.CompareTo(b.Name)); typeMembers[type] = tmp; return tmp; } else { return typeMembers[type]; } }
private TsEnum GenerateEnum(Type type) { var names = type.GetEnumNames(); var values = type.GetEnumValues(); var entries = new Dictionary<string, long?>(); for (int i = 0; i < values.Length; i++) entries.Add(names[i], Convert.ToInt64(values.GetValue(i))); var tsEnum = new TsEnum(GetName(type), entries); this.TypeLookup.Add(type, tsEnum); return tsEnum; }
public static String[] GetNames <TEnum>() where TEnum : struct { Type enumType = typeof(TEnum); return(enumType.GetEnumNames()); }
/// <summary> /// Initializes a new instance of the <see cref="EnumDataEditor"/> class.</summary> /// <param name="theme">The visual theme to use</param> public EnumDataEditor(DataEditorTheme theme, System.Type enumType) : this(theme, enumType.GetEnumNames()) { }
public EnumUITypeEditor(System.Type enumType) : this(enumType.GetEnumNames(), GetIntegerValueArray(enumType)) { }
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); }
private RamlType GetEnum(Type type) { var ramlType = new RamlType { Type = "string", Scalar = new Property { Enum = type.GetEnumNames() } // TODO: check!! }; return ramlType; }
private void GetTypeMembers(List<MemsInfo> tmp,Type type, bool isStatic) { if (type.IsEnum) { foreach (var item in type.GetEnumNames()) { tmp.Add(new MemsInfo(item, type.Name + "." + item, "Is Enum")); } } else if (type.IsClass) { foreach (var item in (from p in type.GetMethods() where p.IsStatic && p.IsPublic select p)) { if (item.Name.IndexOf("get_") == 0 || item.Name.IndexOf("set_") == 0) { continue; } else { MemsInfo x = null; if ((x = tmp.Find(p => p.Name == item.Name)) != null) { x.type += "\r\n" + item.ToString(); } else { MemsInfo method = new MemsInfo(item.Name, item.ToString(), "Is Method"); tmp.Add(method); } } } foreach (var item in (from p in type.GetProperties() select p)) { if (tmp.Find(p => p.Name == item.Name) == null) tmp.Add(new MemsInfo(item.Name, item.ToString(), "Is Properties")); } if (isStatic) { foreach (var item in (from p in type.GetFields() where p.IsStatic && p.IsPublic select p)) { if (tmp.Find(p => p.Name == item.Name) == null) tmp.Add(new MemsInfo(item.Name, item.ToString(), "Is Field")); } } else { foreach (var item in (from p in type.GetFields() where p.IsStatic == false && p.IsPublic select p)) { if (tmp.Find(p => p.Name == item.Name) == null) tmp.Add(new MemsInfo(item.Name, item.ToString(), "Is Field")); } } if (type.BaseType != null) GetTypeMembers(tmp, type.BaseType, isStatic); } }
private Schema CreateEnumSchema(JsonPrimitiveContract primitiveContract, Type type) { var stringEnumConverter = primitiveContract.Converter as StringEnumConverter ?? _jsonSerializerSettings.Converters.OfType<StringEnumConverter>().FirstOrDefault(); if (_describeAllEnumsAsStrings || stringEnumConverter != null) { var camelCase = _describeStringEnumsInCamelCase || (stringEnumConverter != null && stringEnumConverter.CamelCaseText); return new Schema { type = "string", @enum = camelCase ? type.GetEnumNames().Select(name => name.ToCamelCase()).ToArray() : type.GetEnumNames() }; } return new Schema { type = "integer", format = "int32", @enum = type.GetEnumValues().Cast<object>().ToArray() }; }
private DataType GetOrRegister(Type type, bool deferIfComplex, Queue<Type> deferredTypes) { if (_customMappings.ContainsKey(type)) return _customMappings[type](); if (IndeterminateMappings.ContainsKey(type)) return IndeterminateMappings[type](); if (PrimitiveMappings.ContainsKey(type)) return PrimitiveMappings[type](); if (type.IsEnum) return new DataType { Type = "string", Enum = type.GetEnumNames() }; Type innerType; if (type.IsNullable(out innerType)) return GetOrRegister(innerType, deferIfComplex, deferredTypes); Type itemType; if (type.IsEnumerable(out itemType)) { if (itemType.IsEnumerable() && !IsSupportedEnumerableItem(itemType)) throw new InvalidOperationException( String.Format("Type {0} is not supported. Swagger does not support containers of containers", type)); return new DataType { Type = "array", Items = GetOrRegister(itemType, true, deferredTypes) }; } // Anthing else is complex if (deferIfComplex) { if (!_complexMappings.ContainsKey(type)) deferredTypes.Enqueue(type); // Just return a reference for now return new DataType { Ref = UniqueIdFor(type) }; } return _complexMappings.GetOrAdd(type, () => CreateComplexDataType(type, deferredTypes)); }
public BindingEnumCombobox(DataTable dataTable, int index, Type type) { this.dataTable = dataTable; this.index = index; foreach (var name in type.GetEnumNames()) { this.Items.Add(name); } if (string.IsNullOrEmpty(dataTable.Rows[index].ItemArray[1].ToString())) { this.Text = this.Items[0].ToString(); } else { this.Text = dataTable.Rows[index].ItemArray[1].ToString(); } }
private DataType GetOrRegister(Type type, bool deferIfComplex, Queue<Type> deferredTypes) { if (_customMappings.ContainsKey(type)) return _customMappings[type](); if (PrimitiveMappings.ContainsKey(type)) return PrimitiveMappings[type](); if (type.IsEnum) return new DataType { Type = "string", Enum = type.GetEnumNames() }; Type innerType; if (type.IsNullable(out innerType)) return GetOrRegister(innerType, deferIfComplex, deferredTypes); Type itemType; if (type.IsEnumerable(out itemType)) return new DataType { Type = "array", Items = GetOrRegister(itemType, true, deferredTypes) }; // Anthing else is complex if (deferIfComplex) { if (!_complexMappings.ContainsKey(type)) deferredTypes.Enqueue(type); // Just return a reference for now return new DataType { Ref = UniqueIdFor(type) }; } return _complexMappings.GetOrAdd(type, () => CreateComplexDataType(type, deferredTypes)); }
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); }