Proper naming convention for a .NET Delegate type?(.NET 委托类型的正确命名约定?)
问题描述
按照惯例,类通常命名为名词,方法命名为动词,接口命名为形容词.
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.
一些想法:
delegate object ValueExtracting(object container);
delegate object ValueExtractor(object container);
delegate object ValueExtractionHandling(object container);
delegate object ValueExtractionHandler(object container);
推荐答案
我个人使用了几种不同的模式:
Personally I use a couple of different patterns:
[Task][State]Handler
- UITaskFinishedHandler
[Event]Handler
- ControlLoadedHandler
[Function Name]Delegate
- DoSomeWorkDelegate - 当我需要创建委托以在不同/新线程上调用函数时使用
[Function Name]Delegate
- DoSomeWorkDelegate - used when I need to create a delegate for calling a function on a different/new thread
[Task]Callback
- ContainerLoadedCallback - 当控件 A 开始一个动作时使用,该动作由控件 B 完成大部分工作并且控件 A 已将依赖项传递给控件 B(即 ControlA 可能已经传递了一个 UI 容器供 ControlB 填充,并且需要通知才能实际显示该容器)
[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)
当您有一个使用大量多线程或异步 WCF 调用的项目时,最终可能会出现大量委托,因此采用至少对您有意义的标准非常重要.
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.
这篇关于.NET 委托类型的正确命名约定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:.NET 委托类型的正确命名约定?


- 如何用自己压缩一个 IEnumerable 2022-01-01
- 输入按键事件处理程序 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- C# 中多线程网络服务器的模式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01