.NET naming norm Chinese version

xiaoxiao2021-03-06  117

word selection Avoid using type name replicated by the frequently used namespace. The type name cannot be used. The System Collections Forms UI avoids the use of identifiers conflict with commonly used keywords. For example, avoid using the following words.

AddHandler AddressOf Alias ​​And Ansi
As Assembly Auto BitAnd BitNot
BitOr BitXor Boolean ByRef Byte
ByVal Call Case Catch CBool ​​
CByte CChar CDate CDec CDbl
Char CInt Class CLng CObj
Const CShort CSng CStr CType
Date Decimal Declare Default Delegate
Dim Do Double Each Else
ElseIf End Enum Erase Error
Event Exit ExternalSource False Finally
For Friend Function Get GetType
Goto Handles If Implements Imports
In Inherits Integer Interface Is
Let Lib Like Long Loop
Me Mod Module MustInherit MustOverride
MyBase MyClass Namespace New Next
Not Nothing NotInheritable NotOverridable Object
On Option Optional Or Overloads < Br> Overridable Overrides Paramarray Preserve Private
Property Protected Public RaiseEvent Readonly
ReDim Region REM RemoveHandler Resume
Return Select Set Shadows Shared
Short Single Static Step Stop
String Structure Sub SyncLock Then
Throw To True Try TypeOf
Unicode Until Variant When While
With WitHevents Writeonly Xor Eval
Extends InstanceOf Package Var
Identifier (including parameter name) Do not use abbreviations. If you must use abbreviations: Any abbreviation that exceeds more than two characters is used using the Camel uppercase format, even if this is not a standard abbreviation.

The general rules of the namespace namespace are as follows: companyName.technologyName This, the namespace we see should be like this: Microsoft.Office PowerSoft.PowerBuilder Note: This is just a principle. Third-party companies can choose other names. Avoid using the names of the company name or other famous brands as a namespace as a namespace, which causes the possibility of two published namespaces with the same name. (For example, name Microsoft's Office Automatic Class is Microsoft.Office.) Use the Pascal uppercase to separate the logical components (for example, Microsoft.Office.PowerPoint) with comma. If your brand is used by non-traditional uppercase, then you must follow your brand to determine the uppercase way, even in this way, from the usual namespace capital rules (for example, Next.Webobjects, and Ee.cummins.) This time you use a plurality of namespace name. For example, using system.collections instead of system.collection. The special case of this rule is the brand name and abbreviation. For example: using System.IO instead of System.ios. Namespaces and classes cannot use the same name. For example, after a class is named DEBUG, don't use Debug as a namespace name. Names of naming principles for classes and class ingredients Name or noun phrase. Use Pascal uppercase. Reduce the usage of abbreviations in the name. Do not use any type of prefix (such as C). Do not use characters with underscore. Here are some examples of properly named class names. Public class filestream {} public class button {} PUBLIC CLASS STRING {} interface naming principle uses nouns or noun phrases, or describes the adjective word of behavior to name the interface. For example, ICOMPONENT (descriptive noun), ICUSTOMATTRIBUTEPROVIDER (noun phrase), and IPERSISTABLE (adjective). Use Pascal uppercase. Reduce the usage of abbreviations in the interface name. Do not use characters with underscore. Additional prefix i before the interface name to indicate that this type is an interface. Do not add prefix C before class names. Even, it is necessary to add i before the class name does not mean an interface. In this case, as long as the characters behind I can be lowercase (for example, IdentityStore.) When the class is the standard execution of the interface, define this pair of class / interface combinations to use a similar name. The difference between the two names is just an I prefix before the interface. Let's take an example to look at the interface iComponent and its standard execution, class Component. Public interface iComponent {} public class component: iComponent {} public interface iServiceProvider {} PUBLIC INTERFACEPROVIDER {} Attribute Nimer IFATABLE {} Attribute Nightwise Behind the Attribute Suffix, from the defined attribute class. As shown in the following example. Public class obsolettribute {} enum Naming Principle Enum needs to use Pascal uppercase. Enum value is required to use Pascal uppercase. Reduce the usage of abbreviations in the enum name.

Enum is not prefixed before, for example, ADXXX indicates ADO ENUMS, and RTFxxx represents multi-information text enum, and so on.). Do not add an ENUM suffix on the ENUM type. Enum names need to use singular nouns. The complementary noun is used in a specific area. If the value is used in the parameter or attribute, you need to use an enum to define the list value. This tool can know the possible value of an attribute or parameter. Public Enum Filemode {create, createNew, Openorcreate, Truncate} If you use Flags to customize your property using Flags. [Flags] public enum Bindings {CreateInstance, DefaultBinding, ExcatBinding, GetField, GetProperty, IgnoreCase, InvokeMethod, NonPublic, OABinding, SetField SetProperty, Static} package when a Win32 API, there is an exception to this rule. It is common to generate internal definitions from a Win32 header. You can use Win32 capitalization, this form is usually all uppercase. Use INT32 as a foundation type of ENUM. If this enum represents the logo, and the logo is very large (greater than 32), or this Enum can develop into a number of signs in the future, or the type needs to be different from the type INT to be compatible, in this case, in this case special case. ENUM is only used when the value can be completely expressed as a set of position flags. ONUMs cannot be used (eg operating system versions, etc.). Read-only and Const field names, noun phrases, or quarantine names static fields. Use the Pascal to name the static field. Do not use the symbol of the Hungantian type as a prefix of a static field name. The parameter name uses the descriptive parameter name. The parameter name should have sufficient descriptive, so that the parameter name and its type can be used to determine what it means in most cases. Name the parameters with Camel's uppercase. Name the parameters according to the meaning of the parameters, rather than naming according to the type of parameters. We want the development tool to provide information about parameter types in a very convenient way so that the parameter name can be used, which can be described by semantic instead of the species. But occasionally use the parameter name naming according to the type. It is also entirely possible. Do not use the reserved parameters. If more data is needed in the next version, you can increase. Do not use the symbol of the Hungantian type as the prefix of the field name. TYPE GETTYPE (STRING TYPENAME) String Format (String Format, Object [] args method naming principle is used by volatile or verb phrase naming method. Name the method in the Pascal uppercase method shown in the following example. Removeall () getchararray () invoke () property naming principle use name or noun phrase naming property. Use the Pascal to write naming properties. The attribute is the same as the type. When you name your properties with the same name as a type name, the type of this property becomes that type. Although it sounds a little strange, this is correct. The following example uses the principle of attribute naming. Public enum color {...} public class control {public color color color color {get {...} set {...}}} The following example is incorrect.

Public enum color {...} public class control {public int color {get {...} SET {...}}} In that incorrect example, it is impossible to quote Color Enum, because Color XXX will be translated into a member access, which will first get the value of the Color property (INT type), and then access the value of the value (it should be a instance member of System.Int32). The event naming principle uses the EventHandloer suffix naming event handler, as shown in the following. Public Delegate Void MouseEventHandler (Object Sender, MouseEvent E); uses two parameters named Sender and E. The Sender parameter represents an object of the event. The Sender parameter is always a type object, even if it may use a more specific type. The status associated with the event is packaged in an event class example called E. To use the correct, specific event classes of this type. Public Delegate Void MouseEventHandler (Object Sender, MouseEvent E); Named Event Self-variable Class with EventArgs suffix, as shown in the following example. Public class mouseeventargs: Eventargs {Int x; int y; public mouseeventargs (int x, int y) {this.x = x; this.y = y;} public int x {get {return x;}} public int y} Get {return y;}}} Named event name, you need to have a previous and subsequent temptation concept, so use the current timing and past nuts (do not use the Beforexxx / Afterxxx mode). For example, there is a Closing event and a Closed event that can be canceled. Public Event ControleventLer Controladded {// ..} Motive naming event. Case sensitivity Do not use the name that needs to distinguish the case. All components must be fully available in both case sensitive or inappropriate language. Since the language that does not distinguishes is not confirmed in the same environment, the ingredients must be avoided. Do not generate two names that have different namespaces. Namespace EE.CUMMINGS; NAMESPACE EE.CUMMINGS; a type with two parameters, the name of the two parameters cannot only be different cases. Void foo (string a, string a) system.winforms.point p; system.winforms.point pp; a type with two properties, the name of its property cannot be only different cases. INT foo {get, set}; int foo {get, set} There are two types of methods, the name of its method cannot only be different cases. Void foo (); void foo (); Avoiding type names Disappointing different languages ​​using different terms to identify basic management types. Designers must avoid using terms that have specialized requirements for languages. Follow the rules illustrated in this chapter to avoid the case where the type name is confused. Use a semantic meaningful name instead of using the type name. In rare cases, the parameters have no meaning in semantics except types, and the class name is used.

转载请注明原文地址:https://www.9cbs.com/read-126075.html

New Post(0)