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