By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,724 Members | 859 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,724 IT Pros & Developers. It's quick & easy.

Delegate Question

P: n/a
I don't have a copy of Reflector handy :-( so I'd appreciate if someone
could confirm (or clarify) the following.

In consideration of the following delegate declaration...

delegate string MyLovelyDelegate(int parm1, string parm2);
1. Is it true that, in the output assembly, a new class will be created that
inherits from System.MulticastDelegate - and the name of that class is
"MyLovelyDelegate". Yes?

2. Where in the output class (in the output assembly) do the parameters from
my delegate declaration go? Do they go into the constructor of the output
class? Or do they go into the signature of Invoke() and BeginInvoke()?

I appreciate any clarification you can provide.
Oct 17 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Bob Cramer <A@B.comwrote:
I don't have a copy of Reflector handy :-( so I'd appreciate if someone
could confirm (or clarify) the following.

In consideration of the following delegate declaration...

delegate string MyLovelyDelegate(int parm1, string parm2);

1. Is it true that, in the output assembly, a new class will be created that
inherits from System.MulticastDelegate - and the name of that class is
"MyLovelyDelegate". Yes?
Yes.
2. Where in the output class (in the output assembly) do the parameters from
my delegate declaration go? Do they go into the constructor of the output
class? Or do they go into the signature of Invoke() and BeginInvoke()?

I appreciate any clarification you can provide.
The signatures of Invoke and BeginInvoke.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 17 '07 #2

P: n/a

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP*********************@msnews.microsoft.com. ..
Bob Cramer <A@B.comwrote:
>I don't have a copy of Reflector handy :-( so I'd appreciate if
someone
could confirm (or clarify) the following.

In consideration of the following delegate declaration...

delegate string MyLovelyDelegate(int parm1, string parm2);

1. Is it true that, in the output assembly, a new class will be created
that
inherits from System.MulticastDelegate - and the name of that class is
"MyLovelyDelegate". Yes?

Yes.
>2. Where in the output class (in the output assembly) do the parameters
from
my delegate declaration go? Do they go into the constructor of the output
class? Or do they go into the signature of Invoke() and BeginInvoke()?

I appreciate any clarification you can provide.

The signatures of Invoke and BeginInvoke.

Thanks Jon... now a quick followup question. Where do Invoke and BeginInvoke
come from? I was just in MSDN looking at System.Delegate and
MulticastDelegate and those classes do not apparently have those two
methods. Does the compiler insert those methods into the output delegate
class when it is creating the new output class (e.g., MyLovelyDelegate)?


Oct 17 '07 #3

P: n/a
Bob Cramer wrote:
Thanks Jon... now a quick followup question. Where do Invoke and BeginInvoke
come from? I was just in MSDN looking at System.Delegate and
MulticastDelegate and those classes do not apparently have those two
methods. Does the compiler insert those methods into the output delegate
class when it is creating the new output class (e.g., MyLovelyDelegate)?
Yes. See http://msdn2.microsoft.com/en-us/lib....delegate.aspx

Specifically:

Compilers provide two additional methods to the
delegate: BeginInvoke and EndInvoke. For more
information on these methods, see Asynchronous
Programming Overview.

Same thing applies to Invoke.

That's assuming you're talking about the methods on the Delegate class.

There's also Control.Invoke and Control.BeginInvoke. But those don't
include the parameters explicitly in their signatures; it's up to the
caller to put the parameters in an array that represents the parameter
list. So I'm guessing that's not what you meant.

Pete
Oct 17 '07 #4

P: n/a

"Peter Duniho" <Np*********@NnOwSlPiAnMk.comwrote in message
news:13*************@corp.supernews.com...
Bob Cramer wrote:
>Thanks Jon... now a quick followup question. Where do Invoke and
BeginInvoke come from? I was just in MSDN looking at System.Delegate and
MulticastDelegate and those classes do not apparently have those two
methods. Does the compiler insert those methods into the output delegate
class when it is creating the new output class (e.g., MyLovelyDelegate)?

Yes. See http://msdn2.microsoft.com/en-us/lib....delegate.aspx

Specifically:

Compilers provide two additional methods to the
delegate: BeginInvoke and EndInvoke. For more
information on these methods, see Asynchronous
Programming Overview.

Same thing applies to Invoke.

That's assuming you're talking about the methods on the Delegate class.

There's also Control.Invoke and Control.BeginInvoke. But those don't
include the parameters explicitly in their signatures; it's up to the
caller to put the parameters in an array that represents the parameter
list. So I'm guessing that's not what you meant.

Pete
Thanks Pete... yes - I'm referring specifically to BeginInvoke on delegates.
And I did read the link carefully. I am, however confused about the absence
of an Invoke method on the delegate classes. I thought that delegates
offered an Invoke method - but it is clearly not there. I understand that to
invoke a delegate asynchronously we call BeginInvoke and eventulally
EndInvoke. But to invoke a delegate synchronously, we just specify the
delegate instance like we would any method name it references.... i.e., no
".Invoke" method on the delegate instance.

Did delegates ever (perhaps in an early .NET framework version) have a
..Invoke method for delegates (for synchronous invocation)? Am I missing
something or perhaps misguided on that fact?

Thanks again.


Oct 17 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.