Reputation: 653
Where methods BeginInvoke, Invoke, EndInvoke goes from?
I went to MulticastDelegate and Delegate, and they doesn't contain any methods declarations. Of course I understand that signature of this method depends on delegate declarations. But I can't understand how it works.
Here what John Skeet says about it:
Any delegate type you create has the members inherited from its parent types, one constructor with parameters of object and IntPtr and three extra methods: Invoke, BeginInvoke and EndInvoke. We'll come back to the constructor in a minute. The methods can't be inherited from anything, because the signatures vary according to the signature the delegate is declared with. Using the sample code above, the first delegate has the following methods
I'm not native English speaker and I'm a bit confused with fact that
Any delegate type you create has the members inherited from its parent
but then
The methods can't be inherited from anything
Please explain how it works.
Upvotes: 1
Views: 550
Reputation: 101711
Delegates
are special types, that sentence probably means that you can't manually inherit from Delegate
or MulticastDelegate
class because they are special classes.So the C#
compiler creates types that inherits from MulticastDelegate
and declares those methods according to the signature of delegate
type automatically.
Or possibly, it means that since the delegate type changes the signatures of those methods, they are not inherited but instead they created by compiler from scratch, depending on the type of the delegate.(after re-reading, this makes more sense).
Upvotes: 0
Reputation: 296
When the compiler processes the C# delegate type it automatically generates a sealed class deriving from System.MulticastDelegate.
sealed class Add : System.MulticastDelegate
{
public int Invoke(int x, int y);
public IAsyncResult BeginInvoke(int x, int y, AsyncCallback cb, object state);
public int EndInvoke(IAsyncResult result);
}
Upvotes: 0