Let us consider I'm having an application named as AAA.
Now I'm Loading an assembly named as BBB .The assembly BBB is having the declaration of event and delegate.
The handler to the event in BBB is available in AAA.
While loading the assembly BBB, I need to add the handler for the event in AAA.
Whenever the event occur in BBB, I should execute the handler method in AAA.
How to accomplish this?
I coded like this in AAA:
Assembly tstComponent = Assembly.LoadFile(BBB);
Type Global = tstComponent.GetType(ClassInBBB, false, true);
if (Global != null)
{
EventInfo l_objevent = Global.GetEvent("OnGetdelInBBB");
Type l_objEveType = l_objevent.EventHandlerType;
Type Dis = Assembly.GetExecutingAssembly().GetType("AAA", false, true);
MethodInfo l_method = Dis.GetMethod("HandlerinAAA");
Delegate d = Delegate.CreateDelegate(l_objEveType, l_method);
MethodInfo addHandler = l_objevent.GetAddMethod();
Object[] addHandlerArgs = { d };
addHandler.Invoke(Dis, addHandlerArgs);
}
Please help me. Thanks in advance