keyongtech


  keyongtech > dotnet.languages.* > dotnet.languages.csharp > 04/2008

 #1  
04-04-08, 06:35 PM
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.EventHand lerType,
eventHandler);

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

Why ???
Claude
 #2  
04-04-08, 08:39 PM
Ignacio Machin ( .NET/ C# MVP )
On Apr 4, 1:35 pm, Claude <Cla> wrote:
> 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.EventHand lerType,
> 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
Similar Threads
How to retrieve a generic method with GetMethod (reflection) ?

How to retrieve a generic method with GetMethod Code ------------------- #public static void Sort<T>( T[] array, Comparison<T> comparison [System.Reflection.MethodInfo]...

getmethod in reflection

I want use getmethod to get an already known method and invoke it. The problem is, I don't know the parameters of this method, what I have is an Object[] array that contains...

Type.GetMethod with Generic method

I'm trying to get a method using Type.GetMethod. There are two methods with that same name, one is a standard method, the other is a Generic method. How do I get the Generic...

How do I acquire MethodInfo WITHOUT hardcoding the method name in GetMethod!?

hey, How do I acquire MethodInfo WITHOUT hardcoding method name as a string?!??!The fact I have to use xxx.Gettype.GetMethod("MyMethod", xxx) is making me want to drive an...

How do I acquire MethodInfo WITHOUT hardcoding the method name in GetMethod?!

hey, How do I acquire MethodInfo WITHOUT hardcoding method name as a string?!??!The fact I have to use xxx.Gettype.GetMethod("MyMethod", xxx) is making me want to drive an...


All times are GMT. The time now is 11:47 AM. | Privacy Policy