Mont Rothstein <[EMAIL PROTECTED]> wrote:

> new Command(
>       "EditCopy",
>       new Command.ExecuteHandler(OnCopy),
>       new Command.UpdateHandler(UpdateCopyCommand))
> 
> When doing this over and over again it would be much easier if the above
> method call looked like:

You don't need to create the delegate in C# 2.0 and up, the delegate is
created automatically from the method group name (see below) if it can
be resolved and is compatible. Simply declare the arguments as
Command.ExecuteHandler and Command.UpdateHandler, and pass OnCopy and
UpdateCopyCommand, and the C# compiler will insert the delegate
constructor calls automatically.

> new Command("EditCopy", OnCopy, UpdateCopyCommand)
> 
> And then I could create the delegate inside the method.
> 
> This is what I am trying to figure out how to do.

Bare method names don't denote methods - they denote method groups, due
to the fact that OnCopy, UpdateCopyCommand, etc., may be overloaded.
When the receiver (of the method group assignment) is declared to be of
a delegate type, then overload resolution occurs to select the
appropriate overload. Thus, you need to use a delegate in your parameter
list. C# has no facility for synthesizing an e.g. array of MethodInfo
from a method group.

> If this is possible and someone could show me how to declare a method that
> would accept methods like the above example I would appreciate it.

-- Barry

-- 
http://barrkel.blogspot.com/

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to