private void Form1_Load(object sender, System.EventArgs e)
{
// Get the assembly
System.Reflection.Assembly MyAssembly;
MyAssembly = System.Reflection.Assembly.LoadFile(@"C:\Projekt\VS.Net\VBTest\ClassLibrary1\bin\ClassLibrary1.dll");
// Get the module
System.Reflection.Module MyModule;
MyModule = MyAssembly.GetModule("ClassLibrary1.dll");
// Get the type that holds the method to invoke
System.Type MyType;
MyType = MyModule.GetType("ClassLibrary1.Class1");
// Get the method to invoke
System.Reflection.MethodInfo MyMethod;
MyMethod = MyType.GetMethod("Abs");
// Create an instance of the type
Object MyInstance;
MyInstance = Activator.CreateInstance(MyType);
// Invoke the method and show the result
MessageBox.Show(MyMethod.Invoke(MyInstance, new Object[] {-12}).ToString());
// Lets hook up to an event called "MyEvent"
System.Reflection.EventInfo MyEvent;
MyEvent = MyType.GetEvent("MyEvent");
// Create a delegate to our eventhandler procedure
System.Delegate MyDelegate=System.Delegate.CreateDelegate(MyEvent.EventHandlerType,this,"EventHandlerSub");
// Add the eventhandler delegate to the object
MyEvent.AddEventHandler(MyInstance,MyDelegate);
}
// The eventhandler procedure
private void EventHandlerSub(object sender,System.EventArgs e)
{
MessageBox.Show("Event fired!");
}