简体   繁体   English

在C#中将受保护变量编码为Uow或_uow是否正常?

[英]Is it normal practice to code a protected variable as Uow or _uow in C#?

I am coding an application that is similar to the Code Camper application. 我正在编写一个类似于Code Camper应用程序的应用程序。 In this application I see the following code in a controller base: 在这个应用程序中,我在控制器库中看到以下代码:

public abstract class ApiControllerBase : ApiController
{
    protected ICodeCamperUow Uow { get; set; }
}

In the controller: 在控制器中:

public class AttendanceController : ApiControllerBase
{
    public AttendanceController(ICodeCamperUow uow)
    {
        Uow = uow;
    }

I understand that it's normal to have parameters as lowercase in C# but is it normal practice to name the Uow as in the above or would _uow which is what I have been using a naming convention that is more commonly adopted? 我理解在C#中将参数设置为小写是正常的,但通常的做法是将Uow命名为如上所述,或者_uow我使用的命名约定是什么?

The naming conventions in the sample look typical. 示例中的命名约定看起来很典型。 The _ prefix (like _uow ), is typically used with private fields . _前缀(如_uow )通常与私有字段一起使用 There is no private field here; 这里没有私人场地; Uow is a property, and it's protected, not private. Uow是一个属性,它受到保护,而不是私有。

And again, these are just common conventions. 而且,这些只是常见的惯例。 There is nothing in the language to enforce this, and a particular project may depart from this at the discretion of the development team. 语言中没有任何内容可以强制执行此操作,特定项目可能会由开发团队自行决定。

Assuming you are asking about default style as covered on MSDN Capitalization Styles . 假设您询问MSDN 资本化样式中涵盖的默认样式

Since it is property it should use PascalCase, if it would be field it should use lowerCase. 由于它是属性,它应该使用PascalCase,如果它是字段,它应该使用lowerCase。

Note that the name does not seem to follow Abbreviations suggestion. 请注意,该名称似乎不符合缩写建议。

Overall if your codebase follows particular coding guideline and everyone is happy with it - follow the same. 总的来说,如果您的代码库遵循特定的编码指南并且每个人都对此感到满意 - 请遵循相同的规则 For public samples consider following default C# guideline (full word names, no prefixes/underscores, proper casing). 对于公共样本,请考虑遵循默认的C#指南(完整的单词名称,没有前缀/下划线,正确的大小写)。

As a generic guideline from Microsoft themselves for c++, c#, etc 作为微软自己的c ++,c#等通用指南

Do not use underscores, hyphens, or any other nonalphanumeric characters. 请勿使用下划线,连字符或任何其他非字母数字字符。 It's subjective in my opinion, conventions aren't hard and fast rules, most important is the consistency. 在我看来,这是主观的,约定不是硬性规则,最重要的是一致性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM