473,327 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Delegates list

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
Apr 26 '07 #1
3 1614
Lubomir <Lu*****@discussions.microsoft.comwrote:
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 - <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
Apr 26 '07 #2
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 <Lu*****@discussions.microsoft.comwrote:
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 - <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
Apr 26 '07 #3
Lubomir <Lu*****@discussions.microsoft.comwrote:
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 - <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
Apr 27 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jeffrey T. Smith | last post by:
Back when the new J2SE1.5 features were announced, there was a JavaLive community chat (http://java.sun.com/developer/community/chat/JavaLive/2003/jl0729.html) in which Neal Gafter explains the...
3
by: Sam | last post by:
I’m just starting to learn delegates. I’m at the very beginning. If I understand correctly, delegates are for when you want to pass a function as a parameter. For example the client provides a...
4
by: LP | last post by:
Hello! I am still transitioning from VB.NET to C#. I undertand the basic concepts of Delegates, more so of Events and somewhat understand AsyncCallback methods. But I need some clarification on...
4
by: Cedric Rogers | last post by:
I wasn't sure if I could do this. I believe I am stretching the capability of what generics can do for me but here goes. I have a generic delegate defined as public delegate bool...
6
by: Jon Davis | last post by:
I've used delegates fairly heavily for several years in C# for event handling and for starting threads. Does anyone have any real-world scenarios where delegates were both extremely useful and...
2
by: kristian.freed | last post by:
Hi, I currently work in a project written fully in C# where we make extensive use of delegates and events. We have a model where a "state", an object holding data but not much code but which...
6
by: =?Utf-8?B?Sko=?= | last post by:
I have a logger component that logs to multiple sources, ie textfile, eventlog etc. and I have two methods that depending on where I call up my logger comp. one of them will be called. For ex. if...
0
by: bharathreddy | last post by:
Delegates Here in this article I will explain about delegates in brief. Some important points about delegates. This article is meant to only those who already know delegates, it will be a quick...
7
by: Siegfried Heintze | last post by:
I'm studying the book "Microsoft Visual Basic.NET Language Reference" and I would like some clarify the difference between events and delegates. On page 156 I see a WinForms example of timer that...
69
by: raylopez99 | last post by:
They usually don't teach you in most textbooks I've seen that delegates can be used to call class methods from classes that are 'unaware' of the delegate, so long as the class has the same...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.