PC Review


Reply
Thread Tools Rate Thread

Delegates list

 
 
=?Utf-8?B?THVib21pcg==?=
Guest
Posts: n/a
 
      26th Apr 2007
Hi,

I have method that should according an input argument (a collection) call
the appropriate callback delegate.

I am using a list, where I store a struct with fields: delegate, input
argument.

To invoke a proper delegate I have to go through this dictionary, compare
input argument and call delegate if arguments are match.

My question is:
1/ Is there any better way to do it? I don't feel very comfortable with this
solution.
2/ Another method has an argument delegate. This delegate should be removed
from the list and disposed. How will I find the correct delegate to delete?
There is Delegate.Equals method. Again, somhow it feels there should be a
more elegant solution.

Any idea to make it better? I can't use events to call appropriate delegates.

Thanks,
Lubomir
 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      26th Apr 2007
Lubomir <(E-Mail Removed)> wrote:
> I have method that should according an input argument (a collection) call
> the appropriate callback delegate.
>
> I am using a list, where I store a struct with fields: delegate, input
> argument.
>
> To invoke a proper delegate I have to go through this dictionary, compare
> input argument and call delegate if arguments are match.
>
> My question is:
> 1/ Is there any better way to do it? I don't feel very comfortable with this
> solution.


Why not have a dictionary from argument to delegate, and combine the
delegates as you go?

> 2/ Another method has an argument delegate. This delegate should be removed
> from the list and disposed. How will I find the correct delegate to delete?
> There is Delegate.Equals method. Again, somhow it feels there should be a
> more elegant solution.


Delegate.Equals is the way to go here - although it'll be a lot easier
if you also have the argument for which you wish the delegate to be
removed. In the dictionary scenario above, that would then just be a
case of using:

dictionary[specifiedArgument] -= specifiedDelegate;

(That will use Delegate.Equals within Delegate.Remove.)

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
=?Utf-8?B?THVib21pcg==?=
Guest
Posts: n/a
 
      27th Apr 2007
Thanks for answer.

The input argument is a list of possible "flags". The presense at least one
of this flags means I have to invoke a delegate that belongs to this set of
flags. So this input parameter is not suitable to be a key in a dictionary.

Lubomir


"Jon Skeet [C# MVP]" wrote:

> Lubomir <(E-Mail Removed)> wrote:
> > I have method that should according an input argument (a collection) call
> > the appropriate callback delegate.
> >
> > I am using a list, where I store a struct with fields: delegate, input
> > argument.
> >
> > To invoke a proper delegate I have to go through this dictionary, compare
> > input argument and call delegate if arguments are match.
> >
> > My question is:
> > 1/ Is there any better way to do it? I don't feel very comfortable with this
> > solution.

>
> Why not have a dictionary from argument to delegate, and combine the
> delegates as you go?
>
> > 2/ Another method has an argument delegate. This delegate should be removed
> > from the list and disposed. How will I find the correct delegate to delete?
> > There is Delegate.Equals method. Again, somhow it feels there should be a
> > more elegant solution.

>
> Delegate.Equals is the way to go here - although it'll be a lot easier
> if you also have the argument for which you wish the delegate to be
> removed. In the dictionary scenario above, that would then just be a
> case of using:
>
> dictionary[specifiedArgument] -= specifiedDelegate;
>
> (That will use Delegate.Equals within Delegate.Remove.)
>
> --
> Jon Skeet - <(E-Mail Removed)>
> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too
>

 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      27th Apr 2007
Lubomir <(E-Mail Removed)> wrote:
> Thanks for answer.
>
> The input argument is a list of possible "flags". The presense at least one
> of this flags means I have to invoke a delegate that belongs to this set of
> flags. So this input parameter is not suitable to be a key in a dictionary.


It sounds like each flag is a valid key for the dictionary though. When
you're then presented with a set of flags, just fetch the delegates
associated with each of the flags, combine them together, and you're
good to go.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieve/list all my delegates and their permissions all at once =?Utf-8?B?d2hhdGFtYXRjaA==?= Microsoft Outlook VBA Programming 1 8th Sep 2006 10:30 PM
Generics with List and Delegates? =?Utf-8?B?Q2VkcmljIFJvZ2Vycw==?= Microsoft C# .NET 4 28th Jun 2006 09:29 PM
list of Delegates from Outlook Abhi Sharma Microsoft Outlook Calendar 5 19th Apr 2006 03:19 PM
Modify Multicast Delegates List Norbert Microsoft Dot NET Compact Framework 2 7th Jul 2005 08:32 PM
delegates permission using a distribution list Gareth Hutchins Microsoft Outlook 1 8th Oct 2004 04:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:08 AM.