title: How to pass an enum value to the constructor of a class through reflection?
body: <p>i have the class:</p>
  
  <pre><code>public enum ProviderType { SqlClient, OracleClient};
  
  public class ExternalClass
  {
      private string field1;
      private string field2;
      private string EnumsDependance;
  
      public ExternalClass(string p1, string p2, ProviderType type)
      {
          this.field1 = p1;
          this.field2 = p2;
  
          if (type == ProviderType.SqlClient)
          {
              this.EnumsDependance = "SQL TYPE";
          }
          else if (type == ProviderType.OracleClient)
          {
              this.EnumsDependance = "ORACLE TYPE";
          }
          else
          {
              this.EnumsDependance = "NO TYPE";
          }
      }
  }
  </code></pre>
  
  <p>In my program I need to create an instance of this class using reflection, but must pass the constructor of this class the value of the enum, how should I do this? </p>
  
  <p>The program is in a different project ExternalClass and ProviderType, and it must be read by reflection. Here is my sketch:</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          //dynamically load assembly from file ExternalDLL.dll
          Assembly assembly = Assembly.LoadFile(@"C:\temp\ExternalDLL.dll");
  
          //get type of class ProviderType (enum) from just loaded assembly
          Type providerType = assembly.GetType("ExternalDLL.ProviderType");
  
          //get type of class ExternalClass from just loaded assembly
          Type externalClassType = assembly.GetType("ExternalDLL.ExternalClass");
  
          //creating an instance of the class ExternalClass, using reflection
          //constructor -&gt; ExternalClass(string p1, string p2, ProviderType type)
          object externalClassInstance = Activator.CreateInstance(externalClassType, new object[]{"param1", 
                                                                                                  "param2",
                                                                                                  "ENUM VALUE" //how should I pass the value?  
                                                                                                  });
      }
  }
  </code></pre>