C# Reflection Enum Option To Constant Value -


I have code that shows the enum (type of type) option in the straight-forward path from gum

  if (dictionary type == dictionary type rule type) const. DyskTypeId.RegionType; If (dictionary type == dictionary type nationality) return Const.DictionaryTypeId.Nationality;  

Please, assume the guide value to read the best way to read the static option to me.

Thank you in advance

A little later edited: I can not specify any attributes for the calculation options, 'Cos Enumeration Data The model assembly has been declared and the enumeration should not be combined with implementation (Goods, Tables ...)

Answer other than John, you can provide the goods in the form of a field in a separate class, where the f Ld the same name in the same Enum values.

It can be used later to populate a dictionary for quick search:

 using the  system; Using System.Collections.Generic; Namespace SO2856896 {enum dictionary type {area type, nationality} class building {public class dictionary type id {public static guid area type = new guid ("21EC2020-3AEA-1069-A2DD-08002B30309D"); Public Static Guid Nationality = New Guid ("21EC2020-3AEA-1069-A2DD-08002B3030 9E"); }} Class Program {Static Wide Men (String [] ARGs) {Language & lt; Dictionary type, guide & gt; Table = new dictionary & lt; Dictionary Type, Guide & gt; (); Idotype = typef (Const.DictionaryTypeId); Foreach (Type DykeType in Dictionary Enum.GetValues ​​(Typef (Dictionary Type)) {System.Reflection.FieldInfo field = idType .GetField (dicType.ToString (), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags .Public); Guid guid = (Guid) field.GetValue (empty); Table [dit type] = gyd; } Foreach (type the word in the dictionary type Enum.GetValues ​​(typef (type)) {Console.Out.WriteLine (dicType + ":" + [table dicType]); }}}}  

Output:

  field type: 21ec2020-3aea-1069-a2dd-08002b30309d Nationality: 21ec2020-3aea-1069-a2dd-08002b30309e  

I'm not completely sure what I would have chosen myself, but maybe John answered, to see the grids with a dictionary and to populate the reflection on it There is a combination.


Comments