Naming Convention (3) Name and identifier of an identifier
- Naming Conventions (1) Case sensitivity conventions
- Naming Conventions (2) general naming conventions
Program set and DLL name
An assembly is a deployment unit and also represents the identity of the hosted program. Although the Assembly can be distributed in one or more files, an Assembly generally corresponds to only one DLL. The Assembly of the exaggerated file is rarely used, and Visual Studio does not support its built-in.
Namespaces are different from DLL and assembly. namespaces are a set of logical entities for developers, while DLL and assembly are a unit for packaging and deployment. A dll can contain multiple namespaces. Because the namespaces are organized in different ways than a DLL, they can be designed independently without being forcibly associated.
To select a representative name for the Assembly and DLL, such as System. Data, it is easy to know its general functions.
Use the <Company>. <Component>. dll mode to name the DLL. <Component> can contain clauses separated by multiple dots, such as Microsoft. VisualBasic. dll Microsoft. VisualBasic. Vsa. dll.
Namespace name
Namespace template: <Company>. (<Product >|< Technology>) [. <Feature>] [. <Subnamespace>]
Use the company name as the namespace prefix.
Use a stable, version-independent product name as the second layer of the namespace.
Do not determine the namespace hierarchy based on the company's organizational structure, because internal organizations may change after a period of time. Organize and divide the namespace hierarchies based on relevant technologies.
Consider using the plural in The namespace when appropriate. For example, System. Collections
Do not use the same name to name the namespace and type.
Namespace conflicts with class names
Do not introduce too general type names, such as Node, Element, Log, and Message. Such names may cause type name conflicts in common scenarios, a qualifier (XmlNode, FormElement,...) should be added to the generalized type name ,...).
Different namespaces have specific specifications to avoid type name conflicts. The namespace type is as follows:
Application model namespace)
Infrastructure namespace)
Core namespace)
Technology namespace group)
Do not name multiple types in the namespace in a single application model.
Do not name a type that will conflict with any type in the core namespace. For example, Stream can easily conflict with System. IO. Stream.
Do not give names that conflict with other types in the same technology.
Do not introduce a type name conflict between the technical namespace and the type of the application model namespace (unless the two are not intended to be used together ).
Class, structure, and interface naming
The class and structure should be named by a noun or a noun phrase. If you cannot find a noun or noun phrase, you should reconsider the overall design of this type. Another method to select a type name is from the perspective of the scenario.
You must use an adjective phrase to name an interface. In a few cases, you can also use a noun or noun phrase.
Do not prefix the class name with the symbol "C.
The interface name must start with "I". This shows that this type is an interface.
Generic parameter naming
You must use descriptive names to name generic parameters. descriptive names, such as List <T>, Convert <TInput, and TOutput, are not required unless a letter can describe the meaning.
A single letter "T" is used to name the parameter type. If the type has only one type parameter and the type parameter has only one letter.
The descriptive type parameter name must be prefixed with "T.
The constraints applied to this type of parameter are displayed in the type parameter name.
Common Types
If you want to derive a new type from the type included in the. NET Framework, or implement the type in the. NET Framework, you should follow the specifications in the following table.
Name of Enumeration type
You must use singular nouns to name the enumeration type, unless it represents a bit field.
1 public enum ConsoleColor { 2 Black, 3 Blue, 4 Red 5 //... 6 } 7 8 [Flags] 9 public enum ConsoleModifiers { 10 Alt,11 Control,12 Shift13 }
Naming of type members
Use a verb or verb phrase to name a method.
Attribute name
Use nouns, noun phrases, or adjectives to name attributes.
You must name the set attribute in the plural form of the project phrase in the description set, instead of adding the "List" or "Collection" suffix to the singular form of the phrase.
Use affirmative phrases to name Boolean attributes. You Can select prefix "Is", "Can", and "Has.
Consider using the type name of the attribute to name the attribute.
1 public enum Color{/*...*/}2 3 public class Control {4 public Color Color { get; set; }5 }
Event name
Use a verb or verb phrase to name an event.
Use the current time and past time to give the event name the previous and subsequent concepts. For example, Colse event Colosing (before closing) and Colsed (after closing ).
Add the suffix "EventHandler" to name the event handler function (used as the event Delegate.
Use sender and e as the names of two parameters in the event processing function.
Field name
Use a noun, noun phrase, or adjective to name a field.
Do not add a prefix to the field name (static common fields and static protected fields), but you all like to add the "_" prefix to private fields.
For static common fields and static protected fields, use the PascalCasing format.
Parameter Name
Use descriptive parameter names.
You can name a parameter based on the parameter meaning rather than the parameter type.
Names of parameters of overload Operators
You need to use left and right to name the parameters that overload binary operators.
Use value to name the parameters that overload the unary operator.
Consider using meaningful names to name parameters of overload operators.
Do not use abbreviations or numbers when naming parameters of overload operators.
Resource Name
A local resource is like an attribute, so the naming method is similar to that of an attribute.
PascalCasing is case-insensitive when you name a resource key.
To make the name of an identifier descriptive, rather than concise.
Resource names are generally composed of letters, numbers, and underscores. (Sometimes I also use Chinese, but I don't know if there will be any character encoding problems)