.NET naming norm Chinese version

xiaoxiao2021-03-06  44

.NET naming specification Chinese version Add time: 2004-12-20 View: 111 times

Avoid using type names replicated by frequent namespaces that are used. 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.

AddHandlerAddressOfAliasAndAnsiAsAssemblyAutoBitAndBitNotBitOrBitXorBooleanByRefByteByValCallCaseCatchCBoolCByteCCharCDateCDecCDblCharCIntClassCLngCObjConstCShortCSngCStrCTypeDateDecimalDeclareDefaultDelegateDimDoDoubleEachElseElseIfEndEnumEraseErrorEventExitExternalSourceFalseFinallyForFriendFunctionGetGetTypeGoto HandlesIfImplementsImportsInInheritsIntegerInterfaceIsLetLibLikeLongLoopMeModModuleMustInheritMustOverrideMyBaseMyClassNamespaceNewNextNotNothingNotInheritableNotOverridableObjectOnOptionOptionalOrOverloadsOverridableOverridesParamArrayPreservePrivatePropertyProtectedPublicRaiseEventReadOnlyReDimRegionREMRemoveHandlerResumeReturnSelectSetShadowsSharedShortSingleStaticStepStopStringStructureSubSyncLockThenThrowToTrueTryTypeOfUnicodeUntilVariantWhenWhileWithWithEventsWriteOnlyXorevalextendsinstanceofpackagevar identifiers (including the 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 should be like this: Microsoft.OfficePowersoft.PowerBuilder pays attention to: 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. Nomenclature of class and class ingredients Name the clause 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 to use the FLAGS. [Flags] public enum Bindings {CreateInstance, DefaultBinding, ExcatBinding, GetField, GetProperty, IgnoreCase, InvokeMethod, NonPublic, OABinding, SetFieldSetProperty, 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 name, noun phrases, or quarter-free quantisture named 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 with verb or verb phrase naming method. Name the method in the Pascal uppercase method shown in the following example. Removeall () getchararray () invoke () attribute naming principles Name properties with nouns or noun phrases. 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. For example, a class support writes a variety of data types into a stream, which may have the following methods: void write (float value); void write (long value); void write (int value) Void Write (short value); the above example is preferred in the case where the language is specifically required. Void Write (FLOAT FLOATVALUE); void write (long longvalue); void write (int INTVALUE); Void Write (Short ShortValue); Each basic data type requires unique naming in extreme cases In this way, the following general-purpose type name is used. C # type nameVisual Basic type nameJScript type nameVisual C type nameIL representationUniversal type namesbyteSByteSBytecharI1SBytebyteBytebyteunsigned charU1ByteshortShortshortshortI2Int16ushortUInt16UInt16unsigned shortU2UInt16intIntegerintintI4Int32uintNANAunsigned intU4UInt32longLonglong__int64I8Int64ulongUInt64UInt64Unsigned __int64U8UInt64floatSinglefloatfloatR4SingledoubleDoubledoubledoubleR8DoubleboolBooleanbooleanboolI4BooleancharCharcharwchar_tU2CharstringStringStringStringSystem.StringStringobjectObjectObjectObjectSystem.ObjectObject supports a variety of data types read from the stream class can have the following methods. Double readdouble (); float readsingle (); long readin64 (); int tentINT32 (); short readint16 (); The above example is preferred in the case where the language is specifically required. Double readdouble (); float readfloat (); long readlong (); int tentint (); short readshort ();

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

New Post(0)