In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what are the style requirements of. Net project code". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian and go deep into it slowly to study and learn "what are the style requirements of. Net project code" together!
1. C#Code Style Requirements 1.1 Comments
Type, attribute, event, method, method parameter, add comments as needed.
If the names of type, attribute, event, method, and method parameters are already self-explanatory, no comment is required; otherwise, a comment is required.
When adding comments, add them as shown below:
1.2 Naming of types (classes, structs, delegates, interfaces), fields, attributes, methods, events
English is preferred. If there is no suitable word description in English, Pinyin can be used. Using Chinese is not acceptable.
The only place you can use Chinese is for enumerators, which are actually outside the scope of the title of this section. This is just a description put together, as shown in the following figure:
1.3 No abbreviations
All types, methods, parameters and variables must be named without abbreviations, including well-known abbreviations such as msg.
1.4 Code uses semi-expansion
First, open Visual Studio, go to Tools, Options... ", as shown in the following figure:
Step 2: Enter "Text Editor,""C#,""Format Settings,""New Line," and cancel the check marks in all check boxes on the right, as shown in the following figure:
Step 3: Click OK to complete the setup.
1.5 Use Tab as an indent and set the indent size to 4
First, open Visual Studio, go to Tools, Options... ", as shown in the following figure:
Step 2, enter "Text Editor,""C#,""Tabs," as shown below, set tabs.
Step 3: Click OK to complete the setup.
1.6 A.cs source file defines at most two types
If the relationship between two types is closely related, such as product, product type, then the Product class, and ProductType enumeration can be defined in the same Product.cs file.
However, you cannot have two unrelated type definitions in a single.cs file, such as defining the Product class and Reseller class (Distributor) in a single BasicInfo.cs file.
1.7 The type name and source file name must match
When a type is named Product, its source file name can only be Product.cs.
1.8 Pascal style (capitalized word) for all namespaces, type names
As shown in the following figure, red marks are types that use Pascal style:
Note that ProductType is a private type, and regardless of whether the type is public or private, it is always named Pascal-style.
1.9 Camel style for local variables, method parameter names (lowercase first letter followed by capitalized first letter of each word)
Marked in red are variables or method parameters that use Camel style:
1.10 Private methods, protected methods, still Pascal-style naming
The sample code is as follows:
1.11 If the if statement has only one line, you can leave the curly braces, but it must be on the same line as the if statement.
The if statement in Example 1.9 is actually equivalent to the following statement:
1.12 Call other members of the type, add this; call parent class members, add base
The sample code is as follows:
1.13 Private and protected fields inside types, named in Camel style but prefixed with "_"
The code example is as follows:
1.14 Public fields cannot appear
If public fields are required, wrap them with attributes.
1.15 Order of type members
The order of type members from top to bottom is:
Fields: Private, Protected
Attributes: Private, Protected, Public
Events: private events, protected events, public events
Constructors: Constructors with the largest number of arguments, constructors with medium number of arguments, constructors with the smallest number of arguments
Methods: Overloaded methods are arranged in the same order as constructors, from the most arguments to the least arguments.
1.16 Naming of delegates and events
Delegates are named after EventHandler, such as SalesOutEventHandler.
An event is composed of its corresponding delegate type, with the EventHandler suffix removed and the On prefix added.
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 names of methods and properties of bool type
If the method returns a bool type, it is prefixed with Is, Can, or Try, for example:
1.18 Common Collection Type Suffix Naming
The appropriate suffixes shall be added to any set type that meets the criteria listed in the table below.
Description Suffix Sample Array Arrayint[] productArray ListList productListDataTable/HashTableHashTable productTable DictionaryDictionay productDictionaryEF DbSet /DataSetDbSet productSet
1.19 Common suffix naming
All local variables, method parameters, fields and attributes listed in the table below shall be added with corresponding suffixes.
Description Suffix Example Description Cost Related Cost ShipCost Transportation Price Related PriceProductUnitPrice Product Unit Price Message Related Message (Obsolete Note) SuccessMessage Date Related Date OrderDate Order Date Count Quantity Related Count (Obsolete Time) LoginCount Number of Logins Link Address Related UrlBlogUrl Blog Link Picture Related ImageSignImage Signature Picture Amount Related Amount PrepaidAmount Prepayment Points Related PointMemberPoint Member Record Log Related Record (deprecated Log) ErrorRecord Configuration Related ConfigDataBaseConfig Database Configuration Status Related StatusOrderStatus Order Status Mode ModeOpenModeCategory/Type Select One UserCategory User Category Factory Class Related FactoryConnectionFactory Connection Factory Enabled Related EnabledExportEnabled Open Export Stream Related StreamUploadStream Uploader Reader Related ReaderExcelReader Writer Related WriterExcelWriter Excel Writer Adapter Phase AdapterIntroOPAdapterIntroOP Adapter Provider Related ProviderMemebershipProvider Membership Information Provider Wrapper Related WrapperProductWrapperProduct Wrapper Connection Related ConnectionExcelConnectionExcel Connection
1.20 Common type naming
All types in the table below shall be named according to the names specified in the table below.
Type Naming Type Naming Customer Reseller Retailer Dealer User UserInfo (User is database keyword) OrderInfo (Order is database keyword) Supplier Admin Password Member Comments Remember Article News Invoice Import Export Company, Company Profile (deprecated Enterprise) Product Province City District Address Role (deprecated Group) Authority Warehouse Plant Login (Disable SignIn) LogOut Create (Disable Add) Edit Update Remove Photo Photo Image
1.21 Common fields, attribute naming
Fields and attributes are complex, so only the most commonly used items are listed.
Type Name Type Name Id GuidId Id Title Title Remark Remarks Description Memo Description Category Type Linkman Contact
2. XHTML Code Style Requirements 2.1 If XHTML markup has hierarchy, then the code must have hierarchy as well
Here are examples of writing that meets the requirements:
Here are examples of writing that doesn't meet the requirements:
2.2 All markers must be closed
The sample code is as follows:
2.3 If the middle code of the mark exceeds 20 lines, an identification shall be added at the end of the mark
The notation is as follows:
3. CSS Code Style Requirements 3.1 Code Use Semi-Expansion
Refer to Section 1.4 for setting method.
3.2 Use Tab as an indent and set the indent size to 4
Refer to Section 1.5 for setting method.
3.3 code comments
The comment mainly describes which part of the page the style applies to, rather than the effect of the style application. The code comment style is as follows:
3.4 code writing
Each style setting must have one line, not the same line. The following is the required writing:
The following is not required writing:
3.5 Embedded styles are no more than 10 percent of the total stylesheet code
Embedded styles are styles written directly inside HTML tags, as shown below:
3.6 The proportion of inline styles does not exceed 30% of the total stylesheet code
The inline style is the style written in the middle, as shown in the following figure:
Inline style, cannot be written between.
3.7 The proportion of external style sheets is not less than 60% of the total style sheet code
External style sheets are styles written in.css files and introduced into XHTML pages through links, as shown in the following figure:
4. JavaScript Code Style Requirements 4.1 Code Use Semi-Expansion
Refer to Section 1.4 for setting method.
4.2 Use Tab as an indent and set the indent size to 4
Refer to Section 1.5 for setting method.
4.3 code comments
Code comments need to describe "function function","entry parameter" and "return value". Examples of comments are as follows:
The first line describes the function function; the second line describes the entry parameters; and the last line describes the return value.
4.4 No embedded code allowed
Embedded code refers to JavaScript code written in XHTML markup. The following is not acceptable:
4.5 Inline code must not exceed 40% of JavaScript
Inline code is code written between or:
4.6 Outreach code accounts for at least 60% of JavaScript
External code is code written in a separate.js file and then linked to an XHTML page by script tags.
Thanks for reading, hope this article helps!
Thank you for reading, the above is ". Net project code style requirements what" content, after the study of this article, I believe that we have a deeper understanding of the style requirements of. Net project code, the specific use of the need for everyone to practice verification. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.