.NET 委托类型的正确命名约定?

Proper naming convention for a .NET Delegate type?(.NET 委托类型的正确命名约定?)

本文介绍了.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 委托类型的正确命名约定?

基础教程推荐