Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper naming convention for a .NET Delegate type? [closed]

By convention classes are often named like nouns, methods like verbs and interfaces like adjectives.

What is the common naming convention for a delegate? Or what's a good way to differentiate its name when delegates are listed among types and other things?

My immediate assumption is to name a delegate more likely an adjective because a single method interface can often be replaced with a delegate.

Some thoughts:

delegate object ValueExtracting(object container);  delegate object ValueExtractor(object container);  delegate object ValueExtractionHandling(object container);  delegate object ValueExtractionHandler(object container); 
like image 861
John K Avatar asked Feb 27 '10 03:02

John K


People also ask

How do you name delegates?

Since a delegate is something that performs an action (a verb), the delegate should be named what you would call something that performs that action. Take Converter<TInput, TOutput> for example. The verb is Convert. The thing that does the converting is called a converter, hence the name of the delegate.

What is the naming convention in C#?

When naming an interface , use pascal casing in addition to prefixing the name with an I . This clearly indicates to consumers that it's an interface . When naming public members of types, such as fields, properties, events, methods, and local functions, use pascal casing.

What should be the naming convention for methods?

Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized. Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter. Internal words start with capital letters.

What is naming convention and example?

A naming convention can include capitalizing an entire word to denote a constant or static variable (which is commonly done in Flash programming), or it could be a simple character limit in a coding language (such as SQL). Naming conventions have functional as well as organizational qualities.


2 Answers

Personally I use a couple of different patterns:

[Task][State]Handler - UITaskFinishedHandler

[Event]Handler - ControlLoadedHandler

[Function Name]Delegate - DoSomeWorkDelegate - used when I need to create a delegate for calling a function on a different/new thread

[Task]Callback - ContainerLoadedCallback - used when control A starts an action which control B does most of the work and control A has passed a dependency in to control B (i.e. ControlA may have passed a UI container for ControlB to fill and needs notification to actually show the container)

When you have a project that uses a lot of multi threading or async WCF calls you can end up with a lot of delegates floating around, so it is important to adopt a standard that at least makes sense to you.

like image 132
slugster Avatar answered Sep 22 '22 09:09

slugster


Microsoft's Framework Design Guidelines - the naming almanac for me, says the following on the topic:

√ DO add the suffix "EventHandler" to names of delegates that are used in events.
√ DO add the suffix "Callback" to names of delegates other than those used as event handlers.
X DO NOT add the suffix "Delegate" to a delegate.

like image 20
Borislav Ivanov Avatar answered Sep 22 '22 09:09

Borislav Ivanov