string DLLName = "MyDLL.dll"; string ClassName = "MyDll.MyClass"; System.Reflection.Assembly oDLL; object oClass; // This "loads" the .DLL oDLL = System.Reflection.Assembly.LoadFrom(DLLName); // This creates the class instance oClass = oDLL.CreateInstance(ClassName);And if you need to pass parameters
// Create an instance of the desired form from the assembly object [] args = new object[1]; args[0] = MyKey; oForm = (Form)oDLL.CreateInstance(classname, true, System.Reflection.BindingFlags.CreateInstance, null, args, null, null);Code to set/get a property with reflection:
// Setting the MyProperty property in MyObject to "" MyObject.GetType().InvokeMember("MyProperty", System.Reflection.BindingFlags.SetProperty, null, MyObject, new object[] {""}); // Getting the MyProperty property from MyObject: int i = (int)MyObject.GetType().InvokeMember("MyProperty", System.Reflection.BindingFlags.GetProperty, null, MyObject, null);There's also a type.GetProperty() method, Here's a link to Rick Strahl's blog about it:
// Getting properties int i = (int)this.GetType().GetProperty("MyProperty").GetValue(this, null); // Getting Fields are a bit more complicated Label MyLabel = (Label)this.GetType().GetField("MyLabelName", BindingFlags.Instance|BindingFlags.NonPublic).GetValue(this);~~Bonnie