PDF Download: Project Code style requirements V1.0.pdf
The code style is not correct or not, the important thing is uniform, this is a ". Net Project Code style requirements", for your reference.
1. C # code Style requirements 1.1 comments
Type, properties, events, methods, method parameters, and add comments as needed .
If the name of the type, property, event, method, method parameter is already interpreted, you do not need to comment, otherwise you need to add a comment.
When you add a comment, the method is added as shown in the following illustration:
1.2 Name of type (class, struct, delegate, interface), field, property, method, event
English is preferred, if there is no suitable word description, you can use pinyin, the use of Chinese is not in line with the requirements.
The only place you can use Chinese is an enumeration of enumerated items that are not actually part of the title of this section. Here just put together the description, as shown in the following figure:
1.3 Do not use abbreviations
All types, methods, parameters, and variables should not be named using abbreviations, including well-known abbreviations such as MSG.
1.4 Code using half expansion
The first step is to open visual Studio and go to Tools, Options ..., as shown in the following illustration:
Step two, go to the text editor, C #, format, new line, and cancel all the check boxes on the right, as shown in the following illustration:
The third step, click "OK" to complete the setup.
1.5 use Tab as indent and set indent size to 4
The first step is to open visual Studio and go to Tools, Options ..., as shown in the following illustration:
Step two, go to the text editor, C #, tab, and set the tabs as shown in the following illustration.
The third step, click "OK" to complete the setup.
1.6 A. CS source file defines up to two types
If two types of relationships are closely related, such as products, product types, at this point the Product class, and the ProductType enumeration can be defined in the same Product.cs file.
However, you cannot have two unrelated type definitions in a. cs file, such as defining the product class and the Reseller Class (reseller) in a BasicInfo.cs file.
1.7 type name and source file name must be consistent
When a type is named product, its source file name can only be Product.cs.
1.8 All namespaces, type names use Pascal style (capitalize the first letter of the word)
As shown in the following illustration, the red mark is used for Pascal-style types:
Note that ProductType is a private type, and its name is always Pascal-style, regardless of whether the type is public or private.
1.9 Local variables, method parameter names use camel style (first letter lowercase, then capitalize first letter of each word)
Red-labeled variables or method parameters that use the Camel style:
1.10 Private methods, protected methods, still using Pascal style naming
The sample code is as follows:
1.11 If the content of an if statement has only one row, it can be without curly braces, but it must be on the same line as the IF statement
The If judgment in example 1.9 is actually equivalent to the following statement:
1.12 Calling the other members of the type, you need to add this; Call the parent class member, base
The sample code is as follows:
1.13 Private and protected fields within the type, named with Camel style, but with "_" prefix
The code example is as follows:
1.14 cannot appear public field
If a public field is required, use the property to wrap it.
1.15 Order of type members
Type members are sorted in order from top to bottom:
Fields: Private fields, protected fields
Properties: Private property, protected property, public property
Events: Private events, protected events, public events
Constructors: Constructors with the largest number of parameters, constructors with a medium number of arguments, and a constructor with the least number of parameters
Methods: Overloaded methods are arranged in the same order as constructors, from the number of parameters to the least.
1.16 Naming of Delegates and events
Delegates are named EventHandler as suffixes, such as Salesouteventhandler.
event with its corresponding delegate type, remove the EventHandler suffix and add the on prefix to form it.
For example, for an event of the Salesouteventhandler delegate type, the event name is: Onsalesout.
The sample code is as follows:
1.17 Returns the method of bool type, the name of the property
If the type returned by the method is type bool, it is prefixed with is, can, or Try, for example:
1.18 Common collection type suffix naming
The appropriate suffix should be added where the collection type listed in the following table is met.
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 the EF |
Set |
Dbset<product> Productset |
1.19 Common suffix naming
All of the local variables, method parameters, fields, and properties that are listed in the following table need to be appended with the appropriate suffix.
Description |
Suffix |
Example |
Example description |
Cost-related |
Cost |
Shipcost |
Shipping |
Price related |
Price |
Productunitprice |
Product price |
Message-related |
Message (Discard note) |
Successmessage |
Success Message |
Date related |
Date (Discard time) |
OrderDate |
Next single date |
Count, quantity related |
Count (Discard time) |
Logincount |
Number of Logins |
Link Address related |
Url |
Blogurl |
Blog links |
Picture related |
Image |
Signimage |
Signature picture |
Amount related |
Amount |
Prepaidamount |
Advance |
Points, points related |
Point |
Memberpoint |
Member points |
Record, log-related |
Record (discard log) |
Errorrecord |
Error logging |
Configure related |
Config |
Databaseconfig |
Database configuration |
Status related |
Status |
Orderstatus |
Order Status |
Patterns, ways of correlation |
Mode |
OpenMode |
Open mode |
Kinds of related |
Category/type two Select a |
UserCategory |
User type |
Factory class related |
Factory |
ConnectionFactory |
Connect Factory |
Enable related |
Enabled |
Exportenabled |
Open Export |
Flow-related |
Stream |
Uploadstream |
Upload Stream |
Reader related |
Reader |
Excelreader |
Excel Reader |
Writer-related |
Writer |
Excelwriter |
Excel writer |
Adapter-related |
Adapter |
Introopadapter |
Introop Adapter |
Provider-related |
Provider |
Memebershipprovider |
Member Information provider |
Wrapper related |
Wrapper |
Productwrapper |
Product Wrapper |
Connection related |
Connection |
Excelconnection |
Excel connection |
1.20 Common Type naming
Any type that exists in the following table is named after the name specified in the following table.
Type |
Named |
Type |
Named |
Customer |
Customer |
Distributors |
Reseller |
Retailers |
Retailer |
Distributors/Wholesalers |
Dealer |
User |
UserInfo (User is the database key word) |
Order |
OrderInfo (Order for database keywords) |
Suppliers |
Supplier |
Administrator |
Admin |
Password |
Password |
Member |
Member |
Comments |
Remark (Discard comment) |
Article |
Article |
News |
News |
Invoice |
Invoice |
Import |
Import |
Export |
Export |
Companies, enterprises |
Company (Discard Enterprise) |
Products |
Product |
Provinces |
Province |
City |
City |
District |
District |
Address |
Address |
Role |
Role (Discard Group) |
Permissions |
Authority (Discard permission) |
Warehouse |
Warehouse |
Factory |
Plant |
Login |
Login (Discard signin) |
Log out |
LogOut (Discard SignOut) |
Create |
Create (Discard Add) |
Edit |
Edit |
Update |
Update |
Delete |
Remove (Discard Delete) |
Photo |
Photo |
Image |
Image |
1.21 common fields, property naming
Fields, property types are more complex, so only a few of the most commonly used items are listed.
Type |
Name |
Type |
Name |
Id (int type) |
ID ("D" lowercase, discard id) |
Guidid (GUID type) |
Id |
Name |
Name |
Title |
Title |
Remark |
Remarks, descriptions (discard memo, Description) |
Category |
Type (deprecated class, type) |
Linkman |
Contact |
|
|
2. XHTML Code Style Requirements 2.1 If the XHTML markup is layered, then the code has to be layered
The following is an example of a written compliance request:
The following is an example of a write that does not meet the requirements :
2.2 All marks must be closed
The sample code is as follows:
2.3 If the token intermediate code exceeds 20 lines, it should be labeled at the end of the tag
The annotation method is as follows:
3. CSS code style requires 3.1 code to use half expansion
Set method reference section 1.4.
3.2 Use Tab as indent and set indent size to 4
Set method Reference section 1.5.
3.3 Code comments
Note The main description of the style applied to which part of the page, rather than the application of the description style, the code comment style is as follows:
3.4 Code Writing
Each style setting must have a single line and cannot be on the same line, and the following is the wording that meets the requirements:
The following are the written wording that does not meet the requirements :
3.5 Inline styles do not exceed 10% of the total style sheet code
Inline styles are styles written directly inside HTML tags, as shown in the following illustration:
3.6 inline style does not exceed 30% of the total style sheet code
Inline style is the style written in
Inline style, cannot be written between <body></body>.
3.7 The scale of an outer style sheet is not less than 60% of the total style sheet code
The inline style sheet is a style that is written in a. css file and is introduced to the XHTML page by link, as shown in the following illustration:
4. JavaScript code style requires 4.1 code to use half expansion
Set method reference section 1.4.
4.2 Use tab as indent and set indent size to 4
Set method Reference section 1.5.
4.3 Code comments
Code comments need to explain function functions, entry parameters, return values, and the following example:
The first line describes the function, the second line describes the entry parameter, and the last line shows the return value
4.4 No inline code appears
Inline code refers to the JavaScript code written in the XHTML markup, which is not in accordance with the requirements of the following wording:
4.5 Inline code in the total number of JavaScript must not exceed 40%
Inline code refers to code written between
4.6 The total number of JavaScript in the outer-line code is at least 60%
The external code refers to the code that is written in a separate. js file and then connected to the XHTML page through a script tag.
Thanks for reading, hope this article can bring you help!