title: Getting Enum from a Dynamically created Enum
body: <p>Can you help me with this, in C#</p>
  
  <p>Given an Enum </p>
  
  <pre><code>public enum InterferenceEnum
      {
          None = 0,
          StrongNoiseSource = 1,
          MediumNoiseSource = 2,
          VerySensitiveSignal = 4,
          SensitiveSignal = 8,
      }
  </code></pre>
  
  <p>and a Dynamic Enum from this </p>
  
  <pre><code>public Type GenerateEnumerations(List&lt;string&gt; lEnumItems, string assemblyName)
      {
          //    Create Base Assembly Objects
          AppDomain appDomain = AppDomain.CurrentDomain;
          AssemblyName asmName = new AssemblyName(assemblyName);
          AssemblyBuilder asmBuilder = appDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run);
  
          //    Create Module and Enumeration Builder Objects
          ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule(assemblyName + "_module");
          EnumBuilder enumBuilder = modBuilder.DefineEnum(assemblyName, TypeAttributes.Public, typeof(int));
          enumBuilder.DefineLiteral("None", 0);
          int flagCnt = 1;
          foreach (string fmtObj in lEnumItems)
          {
              enumBuilder.DefineLiteral(fmtObj, flagCnt);
              flagCnt++;
          }
          var retEnumType = enumBuilder.CreateType();
          //asmBuilder.Save(asmName.Name + ".dll");
          return retEnumType;
      }
  </code></pre>
  
  <p>using the function above</p>
  
  <pre><code>List&lt;string&gt; nets_List = new List&lt;string&gt;() { "A", "B", "C" };
  netListEnum = GenerateEnumerations(nets_List, "netsenum");
  </code></pre>
  
  <p>Now if i have a variable with value "None", i can get the enum by</p>
  
  <pre><code>SomeEnum enum = (SomeEnum)Enum.Parse(typeof(SomeEnum), "EnumValue");
  </code></pre>
  
  <p>using the first Enum, i can get the enum of string "None"</p>
  
  <pre><code>InterferenceEnum enum = (InterferenceEnum)Enum.Parse(typeof(InterferenceEnum), "None");
  </code></pre>
  
  <p>How can i get the enum for the dynamic generated enum?</p>
  
  <pre><code>var enum = (netListEnum.GetType())Enum.Parse(typeof(netListEnum.GetType()), "None"); 
  </code></pre>
  
  <p>the above code is wrong because i still "casting" it with the netListEnum Type, here is the updated code</p>
  
  <pre><code>var enum = Enum.Parse(netListEnum, "None"); 
  </code></pre>