Re: Looking to make something like a delegate...

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Jon,

If I pass the delegate as a parameter then I cannot set the delegate's
parameter values. I would also have to pass an object array that
contains all the parameters and hope that they are in the correct
order, and the correct number of them.

Like...

cls2.MyMethod(myDel, new object[] { "How old are you?", 0 });

I have this working fine. But, you lose the benefit of intellisense
and making sure the parameters are typed and passed properly. That is
why i would like to be able to write...

cls2.MyMethod(myDel("How old are you?", 0));

What i want to do is just have the delegate functionality but when the
Invoke method is called, it does what I want it to do and not just
invoke the method the delegate is pointed to.

Make sense?


Jon Shemitz wrote:
matsi.inc@xxxxxxxxx wrote:

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.

Perhaps I'm missing something - why don't you just write cls2.MyMethod
to take a MyDelegate parameter?

--

.NET 2.0 for Delphi Programmers
www.midnightbeach.com/.net

.



Relevant Pages

  • Re: Delegates and threads
    ... > Please could someone give me a simple exampe of how to get a delegate passed to my worked class so that my main form can update ... a method to update a progress bar. ... > Invoke to marshal the call to the UI is plain silly. ... >>> private void UpdateProgressCore ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Threading Advice Quick Question
    ... You can do this by using a Delegate, just invoke the delegate after ... operations (let's call these classes the business layer) and notify the ... client of their completion via callback methods then the clients of these ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Looking to make something like a delegate...
    ... using the delegate above... ... MyAssembly.MyClass cls = new MyAssembly.MyClass; ... MyDelegate myDel = new MyDelegate; ... the origin of the delegate, extract the parameter values, and invoke ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Clarification on use of Control.Invoke()
    ... me take the Enabled property as an example for the rest of my questions. ... Since control.Invoketakes a delegate with a void parameter list as it's ... Can anyone show me an example of how to use Invoke() to return a value from ... >>control as well, from any thread other than the one where the control is ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: Passing reference of the main thread control
    ... works fine with Invoke() and delegates, but both threads are in the same ... puplic delegate void SimbuttonCaptureStream( ... and event patterns both are examples of what I'm talking about, ... demonstrates the callback pattern, and as I said, the entire ...
    (microsoft.public.dotnet.languages.csharp)