M
matsi.inc
I am looking to make something like a delegate that i can use in my
projects but am having a hard time getting started.
The behavior I am most interested in is how a delegate changes it's
Invoke method dynamically to match the arguments supplied to it when it
is defined. For example...
public delegate void MyDelegate(string myString, int myInt);
MyDelegate myDel = new MyDelegate(my.Target);
When I look at the Invoke method for myDel, you see...
myDel.Invoke(string myString, int myInt);
What I am ultimately looking to do is override the Invoke method of a
delegate but being that the Delegate class is locked, I can't just do
it the easy way.
My ultimate goal is to be able to pass a method invocation as a
parameter without it being invoked. As an example...
... using the delegate above...
MyAssembly.MyClass cls = new MyAssembly.MyClass();
MyDelegate myDel = new MyDelegate(cls.targetMethod);
MyAssembly.MyClass2 cls2 = new MyAssembly.MyClass2();
cls2.MyMethod(myDel("How old are you?", 0));
When this is run, the MyMethod on cls2 will use reflection to determine
the origin of the delegate, extract the parameter values, and invoke
the method. This is what I would like to do.
Even to understand/learn how a delegate definition allows for a
variable number of parameters to be defined, and then turn around and
create an Invoke method on the delegate that matches these parameters
would be a great deal of help.
Any help, suggestions, alternatives would be greatly appreciated.
projects but am having a hard time getting started.
The behavior I am most interested in is how a delegate changes it's
Invoke method dynamically to match the arguments supplied to it when it
is defined. For example...
public delegate void MyDelegate(string myString, int myInt);
MyDelegate myDel = new MyDelegate(my.Target);
When I look at the Invoke method for myDel, you see...
myDel.Invoke(string myString, int myInt);
What I am ultimately looking to do is override the Invoke method of a
delegate but being that the Delegate class is locked, I can't just do
it the easy way.
My ultimate goal is to be able to pass a method invocation as a
parameter without it being invoked. As an example...
... using the delegate above...
MyAssembly.MyClass cls = new MyAssembly.MyClass();
MyDelegate myDel = new MyDelegate(cls.targetMethod);
MyAssembly.MyClass2 cls2 = new MyAssembly.MyClass2();
cls2.MyMethod(myDel("How old are you?", 0));
When this is run, the MyMethod on cls2 will use reflection to determine
the origin of the delegate, extract the parameter values, and invoke
the method. This is what I would like to do.
Even to understand/learn how a delegate definition allows for a
variable number of parameters to be defined, and then turn around and
create an Invoke method on the delegate that matches these parameters
would be a great deal of help.
Any help, suggestions, alternatives would be greatly appreciated.