Reflection provides objects (of type Type) that encapsulate assemblies, modules and types. You can use reflection to dynamically create an instance of a type, bind the type to an existing object, or get the type from an existing object and invoke its methods or access its fields and properties
I have Used reflection for dynamically load assembly and display its forms with the help of Reflection.
Step 1: Loading an assembly form the specified path.
string path = Directory.GetCurrentDirectory() + @"\dynamicdll.dll";
try
{
asm = Assembly.LoadFrom(path);
}
catch (Exception)
{
}
Step 2: Getting all forms of an assembly dynamically & adding them to the list type.
List<Type> FormsToCall = new List<Type>();
Type[] types = asm.GetExportedTypes();
foreach (Type t in types)
{
if (t.BaseType.Name == "Form")
FormsToCall.Add(t);
}
Step 3:
int FormCnt = 0;
Type ToCall;
while (FormCnt < FormsToCall.Count)
{
ToCall = FormsToCall[FormCnt];
//Creates an instance of the specified type using the constructor that best matches the specified parameters.
object ibaseObject = Activator.CreateInstance(ToCall);
Form ToRun = ibaseObject as Form;
try
{
dr = ToRun.ShowDialog();
if (dr == DialogResult.Cancel)
{
cancelPressed = true;
break;
}
else if (dr == DialogResult.Retry)
{
FormCnt--;
continue;
}
}
catch (Exception)
{
}
FormCnt++;
}
solved Something like Reflections in Java for .NET [closed]