Using reflection, I need to investigate a user DLL and create an object of a class in it.
What is the simple way of doing it?
Try Activator.CreateInstance.
System.Reflection.Assembly
is the class you will want to use. It contains many method for iterating over the types contained with a user DLL. You can iterate through each class, perhaps see if it inherits from a particular interface etc.
http://msdn.microsoft.com/en-us/library/system.reflection.assembly_members.aspx
Investigate Assembly.GetTypes()
method for getting the list of types, or Assembly.GetExportedTypes()
for the public ones only.
You can create an instance of a class from a Type object using Activator.CreateInstance, to get all types in a dll you can use Assembly.GetTypes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With