Proper naming convention for a .NET Delegate type?

后端 未结 8 1993
我寻月下人不归
我寻月下人不归 2020-12-12 11:29

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

相关标签:
8条回答
  • 2020-12-12 12:11

    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.

    0 讨论(0)
  • 2020-12-12 12:12

    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.

    0 讨论(0)
提交回复
热议问题