Reflection : GetEvent, GetMethod, Bind Method on Event

  • Thread starter Thread starter Claude
  • Start date Start date
C

Claude

TValue oItem = (TValue)Activator.CreateInstance(typeof(TValue),
BindingFlags.Instance | BindingFlags.NonPublic,
null,
new object[] { m_nCleTemporaire },
System.Globalization.CultureInfo.CurrentCulture);

EventInfo oPropertyChanged = oItem.GetType().GetEvent("PropertyChanged");
MethodInfo eventHandler = this.GetType().GetMethod("Item_PropertyChanged",
BindingFlags.Instance | BindingFlags.NonPublic);

/** Next code line fails **/
Delegate d = Delegate.CreateDelegate(oPropertyChanged.EventHandlerType,
eventHandler);

The system says that it cannot murge the delegate with the defined type.

Why ???
Claude
 
TValue oItem = (TValue)Activator.CreateInstance(typeof(TValue),
                         BindingFlags.Instance |BindingFlags.NonPublic,
                         null,
        new object[] { m_nCleTemporaire },                                 
                        System.Globalization.CultureInfo.CurrentCulture);

EventInfo oPropertyChanged = oItem.GetType().GetEvent("PropertyChanged");
MethodInfo eventHandler = this.GetType().GetMethod("Item_PropertyChanged",  
BindingFlags.Instance | BindingFlags.NonPublic);

/** Next code line fails **/
Delegate d = Delegate.CreateDelegate(oPropertyChanged.EventHandlerType,
eventHandler);

The system says that it cannot murge the delegate with the defined type.

Why ???
 Claude

Are you sure that PropertyChanged event is of type EventHandlerType?
Most usually you get this error because of that
 
Back
Top