Looking to make something like a delegate...



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.

.



Relevant Pages

  • Re: Looking to make something like a delegate...
    ... I took a look at the generics and they ... delegate with, the Invoke method matches those parameters. ... or the compiler generated class is not sealed. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Delegates and the Invoke method
    ... Public is a way of saying that anyone can access the delegate. ... The Form class and the Button class do not have a Left property. ... you should note that the Invoke method on the Form/Button class is ... MyDelegate MyDelegateVar = MyMethod ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Looking to make something like a delegate...
    ... I have a class with a login method and delegate... ... MySecurityClass security = new MySecurityClass; ... Invoke method is called, it does what I want it to do and not just ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: how can i execute a delegate on the thread that created the object
    ... Implement invoke method in your object. ... Overloads Public Overridable Function Invoke(_ ... ByVal method As Delegate, _ ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Delegate.DynamicInvoke workaround
    ... knowledge about the "ListChangedEventHandler" that derived Delegate. ... which doesn't have the Invoke method. ... that is akin to reference ...
    (microsoft.public.dotnet.framework.compactframework)