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



Then do your hook before you call the delegate. Then call the delegate.
Maybe you could expand on what your asking.

--
William Stacey [C# MVP]

<matsi.inc@xxxxxxxxx> wrote in message
news:1169156194.853971.49780@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
| Stoitcho,
|
| Thanks for the information. I took a look at the generics and they
| don't really solve my problem of what I am wanting to do. I may be
| being picky here, but it just seems that I should be able to mimic the
| behavior of anything provided in the framework exactly. What I like
| about the delegate is that no matter how many parameters you define the
| delegate with, the Invoke method matches those parameters. What i do
| not like, is when you call Invoke, it automatically calls the target
| method with the supplied parameter values. What i want to do is
| intercept this invocation and do something else with the information
| provided by the delegate invocation (method and parameter values). So,
| i dont really want a delegate, but i want something that behaves like
| one.
|
| Any ideas?
|
| Stoitcho Goutsev (100) wrote:
| > Hi,
| >
| > when you declare a delegate the compiler actually generates a new class
that
| > inherits from the MulticastDelegate class (which inherits from Delegate)
and
| > declares the Invoke method with desired signature.
| >
| > If by locked you mean sealed then no, neither Delegate nor
MulticastDelegate
| > or the compiler generated class is not sealed. The only think is that
you
| > cannot use them as a base class because the compiler doesn't allow you
to.
| > The compiler allows you only to use its syntax for declaring delegates.
On
| > the other hands for more configurable delegates you can use generics -
| > Generic Delegates.
| >
| > For more info look at:
| > http://msdn2.microsoft.com/en-us/library/sx2bwtw7(VS.80).aspx
| >
| >
| > --
| > HTH
| > Stoitcho Goutsev (100)
| >
| > <matsi.inc@xxxxxxxxx> wrote in message
| > news:1169148669.300089.214660@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
| > >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)

Loading