.NET代理类型的正确命名约定? [英] Proper naming convention for a .NET Delegate type?

查看:64
本文介绍了.NET代理类型的正确命名约定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

常规类通常被命名为名词,诸如动词和形容词等接口的方法。



代理的常见命名约定是什么?或者当代表在类型和其他事物中列出时,区分其名称的好方法是什么?



我的立即假设是将代表命名为形容词因为一个方法接口通常可以被一个代理替换。



有些想法:

 委托对象ValueExtracting(object container); 

委托对象ValueExtractor(对象容器);

委托对象ValueExtractionHandling(object container);

委托对象ValueExtractionHandler(object container);


解决方案

个人我使用几种不同的模式: p>

[任务] [状态]处理程序 - UITaskFinishedHandler



[Event] Handler - ControlLoadedHandler



[功能名称]委托 - DoSomeWorkDelegate - 当我需要创建一个委托以在不同/新线程上调用函数时使用



[任务]回调 - ContainerLoadedCallback - 当控件A启动一个控制B执行大多数工作和控制A已经通过依赖关系来控制B(即ControlA可能已经通过ControlB填充的UI容器并且需要通知来实际显示容器)



当你有一个使用大量多线程或异步WCF调用的项目,最终可能会有很多代理浮动,所以重要的是采用标准的至少对你有意义。


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);

解决方案

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.

这篇关于.NET代理类型的正确命名约定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆