Document directory
- 1.1 annotations
- 1.2 type (class, structure, Delegate, interface), field, attribute, method, and event naming
- 1.3 do not use abbreviations.
- 1.4 code semi-expanded
- 1.5 Use Tab as indent and set the indent size to 4
- 1.6 One. cs source file defines at most two types
- 1.7 The type name and source file name must be consistent
- 1.8 all namespaces and type names use the Pascal style (uppercase letters)
- 1.9 local variables and method parameter names use the Camel style (the first letter is lowercase, And the last letter is the first letter of each word)
- 1.10 private and protected methods are still named in Pascal Style
- 1.11 if the if statement contains only one row, no curly braces can be added, but it must be in the same line as the if statement.
- 1.12 this must be added to other members of the call type. To call a parent class member, the base must be added.
- Private and protected fields in the 1.13 type are named in the Camel style but prefixed "_".
- 1.14 public fields cannot appear
- 1.15 sorting order of type members
- 1.16 delegate and event naming
- 1.17 return the names of methods and attributes of the bool type.
- 1.18 common set type suffix naming
- 1.19 common suffix naming
- 1.20 naming of common types
- 1.21 common fields and attribute names
- 2.1 If the XHTML mark has layers, the Code should also have layers
- 2.2 All tags must be closed
- 2.3 if more than 20 lines of intermediate code are marked, the mark should be added at the end of the mark
- 3.1 code semi-expanded
- 3.2 use Tab as indent and set the indent size to 4
- 3.3 code comments
- 3.4 code writing
- 3.5 The ratio of embedded styles cannot exceed 10% of the total amount of style sheet code
- 3.6 The ratio of inline styles does not exceed 30% of the total amount of style table code
- 3.7 The proportion of external style tables should not be less than 60% of the total style table code
- 4.1 code semi-expanded
- 4.2 Use Tab as indent and set the indent size to 4
- 4.3 code comments
- 4.4 embedded code is not allowed
- 4.5 Inline code cannot exceed 40% of JavaScript total
- 4.6 external code accounts for at least 60% of JavaScript's total
Address: http://www.cnblogs.com/JimmyZhang/archive/2013/06/05/3118936.html
Download PDF: project code requires v1.0.pdf
The Code style is not correct or not. The most important thing is uniformity. This is a project code style requirement I have prepared for your reference.
1. C # code style requirements 1.1 comments
Type, attribute, event, method, and method parameters. Add comments as needed.
If the names of types, properties, events, methods, and method parameters are self-explanatory, you do not need to add comments; otherwise, you must add comments.
Shows how to add a comment:
1.2 type (class, structure, Delegate, interface), field, attribute, method, and event naming
English is preferred. If there is no proper word description in English, you can use Pinyin instead of Chinese.
The only thing that can be used in Chinese is the enumerated items. The enumerated items do not actually fall into the category of the title in this section. Here is just a description, as shown in:
1.3 do not use abbreviations.
Names of all types, methods, parameters, and variables cannot be abbreviated, including well-known abbreviations, such as msg.
1.4 code semi-expanded
Step 1: Open Visual Studio and go to "Tools" and "Options...", as shown in:
Step 2: Go to "Text Editor", "C #", "format settings", and "new line", and cancel the check boxes on the right, as shown in:
Step 3: click "OK" to complete the settings.
1.5 Use Tab as indent and set the indent size to 4
Step 1: Open Visual Studio and go to "Tools" and "Options...", as shown in:
Step 2: Go to "Text Editor", "C #", and "tab", as shown in, and set tabs.
Step 3: click "OK" to complete the settings.
1.6 One. cs source file defines at most two types
If the relationship between the two types is closely related, such as the Product and Product types, the Product class and ProductType enumeration can be defined in the same Product. cs file.
However, there cannot be two irrelevant Type Definitions in A. cs file, for example, defining the Product class and Reseller class (distributor) in a BasicInfo. cs file.
1.7 The type name and source file name must be consistent
When the type is Product, the source file name can only be Product. cs.
1.8 all namespaces and type names use the Pascal style (uppercase letters)
As shown in, red marks the Pascal-style type:
Note that ProductType is a private type. Whether the type is public or private, it is always named in Pascal style.
1.9 local variables and method parameter names use the Camel style (the first letter is lowercase, And the last letter is the first letter of each word)
Variables or method parameters marked in red using the Camel style:
1.10 private and protected methods are still named in Pascal Style
The sample code is as follows:
1.11 if the if statement contains only one row, no curly braces can be added, but it must be in the same line as the if statement.
The if judgment in example 1.9 Is Actually equivalent to the following statement:
1.12 this must be added to other members of the call type. To call a parent class member, the base must be added.
The sample code is as follows:
Private and protected fields in the 1.13 type are named in the Camel style but prefixed "_".
The sample code is as follows:
1.14 public fields cannot appear
To use public fields, use attributes for packaging.
1.15 sorting order of type members
The sorting order of type members is from top to bottom:
Field: Private field, protected field
Attributes: private, protected, and public attributes
Events: private events, protected events, and public events
Constructor: constructor with the largest number of parameters. constructor with the lowest number of parameters
Method: The sorting order of the overload method is the same as that of the constructor. the maximum number of parameters is down to the minimum number of parameters.
1.16 delegate and event naming
The delegate is named after EventHandler, for example, SalesOutEventHandler.
The event is composed of the EventHandler suffix and the On prefix.
For example, for events of the SalesOutEventHandler delegate type, the event name is OnSalesOut.
The sample code is as follows:
1.17 return the names of methods and attributes of the bool type.
If the type returned by a method Is bool, its prefix Is, Can, or Try. For example:
1.18 common set type suffix naming
If the set types listed in the following table are met, the corresponding suffixes should be added.
Description |
Suffix |
Example |
Array |
Array |
Int [] productArray |
List |
List |
List <Product> productList |
DataTable/HashTable |
Table |
HashTable productTable |
Dictionary |
Dictionary |
Dictionay <string, string> productDictionary |
DbSet/DataSet in EF |
Set |
DbSet <Product> productSet |
1.19 common suffix naming
All local variables, method parameters, fields, and attributes listed in the following table must be suffixed.
Description |
Suffix |
Example |
Example |
Cost-related |
Cost |
ShipCost |
Transportation fee |
Pricing |
Price |
ProductUnitPrice |
Unit Price |
Message-related |
Message (discard Note) |
SuccessMessage |
Successful message |
Date-related |
Date (discard Time) |
OrderDate |
Order Date |
Count and quantity |
Count (discard Time) |
LoginCount |
Logon count |
Link address |
Url |
BlogUrl |
Blog Link |
Image problems |
Image |
SignImage |
Signature Image |
Amount |
Amount |
PrepaidAmount |
Prepayment |
Points and points |
Point |
MemberPoint |
Member points |
Logs |
Record (discard Log) |
ErrorRecord |
Error records |
Configuration |
Config |
DataBaseConfig |
Database Configuration |
Status |
Status |
OrderStatus |
Order Status |
Modes and methods |
Mode |
OpenMode |
Open Mode |
Type-related |
Either Category or Type |
UserCategory |
User Type |
Factory Problems |
Factory |
ConnectionFactory |
Connection Factory |
Enable |
Enabled |
ExportEnabled |
Enable Export |
Stream-related |
Stream |
UploadStream |
Upload stream |
Reader-related |
Reader |
ExcelReader |
Excel Reader |
Writer-related |
Writer |
ExcelWriter |
Excel writer |
Adapter Problems |
Adapter |
IntroOPAdapter |
IntroOP Adapter |
Providers |
Provider |
MemebershipProvider |
Member information provider |
Wrapper Problems |
Wrapper |
ProductWrapper |
Product Package |
Connection problems |
Connection |
ExcelConnection |
Excel connection |
1.20 naming of common types
All types in the following table must be named by the name specified in the following table.
Type |
Name |
Type |
Name |
Customer |
Customer |
Distributors |
Reseller |
Retailers |
Retailer |
Distributors/wholesalers |
Dealer |
User |
UserInfo (User is the database keyword) |
Order |
OrderInfo (Order is the database keyword) |
Supplier |
Supplier |
Administrator |
Admin |
Password |
Password |
Member |
Member |
Comment |
Remark (discard Comment) |
Article |
Article |
News |
News |
Invoice |
Invoice |
Import |
Import |
Export |
Export |
Companies, enterprises |
Company (discard Enterprise) |
Product |
Product |
Province |
Province |
City |
City |
Districts and counties |
District |
Address |
Address |
Role |
Role (discard Group) |
Permission |
Authority (discard Permission) |
Warehouse |
Warehouse |
Factory |
Plant |
Login |
Login (discard SignIn) |
Logout |
LogOut (discard SignOut) |
Create |
Create (discard Add) |
Edit |
Edit |
Update |
Update |
Delete |
Remove (discard Delete) |
Photo |
Photo |
Image |
Image |
1.21 common fields and attribute names
Fields and attribute types are complex, so only the most common items are listed.
Type |
Name |
Type |
Name |
Id (int type) |
Id ("d" in lower case, discard ID) |
GuidId (Guid type) |
Id |
Name |
Name |
Title |
Title |
Remark |
Remarks and descriptions (discard Memo and Description) |
Category |
Type (disallow Class and Type) |
Linkman |
Contact |
|
|
2. XHTML code style requirement 2.1 If the XHTML mark has layers, the Code should also have layers
The following is an example of writing a document that meets the requirements:
Below is the writingNon-conformingExample:
2.2 All tags must be closed
The sample code is as follows:
2.3 if more than 20 lines of intermediate code are marked, the mark should be added at the end of the mark
The annotation method is as follows:
3. CSS code style requirements 3.1 code should be semi-expanded
For the setting method, see section 1.4.
3.2 use Tab as indent and set the indent size to 4
For the setting method, see section 1.5.
3.3 code comments
The comment mainly describes the part of the style applied to the page, rather than the effect of the style. The code comment style is as follows:
3.4 code writing
Each style setting must have an exclusive row and cannot be located in the same row. The following statements meet the requirements:
Below isNon-conformingStatement:
3.5 The ratio of embedded styles cannot exceed 10% of the total amount of style sheet code
Embedded styles are styles that are directly written in HTML labels, as shown in:
3.6 The ratio of inline styles does not exceed 30% of the total amount of style table code
Inline styles are styles written in
Inline style,NoBetween <body> </body>.
3.7 The proportion of external style tables should not be less than 60% of the total style table code
The external style table is a style written in the. CSS file and is introduced to the XHTML page through link, as shown in:
4. JavaScript code style requirements 4.1 code should be semi-expanded
For the setting method, see section 1.4.
4.2 Use Tab as indent and set the indent size to 4
For the setting method, see section 1.5.
4.3 code comments
The "function", "entry parameters", and "return values" must be described in the code annotation. The annotation example is as follows:
The first line describes the function, the second line describes the entry parameters, and the last line describes the return values.
4.4 embedded code is not allowed
Embedded Code refers to the JavaScript code written in the XHTML mark. The following code is as follows:Non-conformingOf:
4.5 Inline code cannot exceed 40% of JavaScript total
Inline code refers to the code written between
4.6 external code accounts for at least 60% of JavaScript's total
External Code refers to the code written in a separate. js file, and then linked to the XHTML page by marking the script.
Thank you for reading this article. I hope this article will help you!