Code Specification (CS)
General rule
1.1. Purpose
In order to properly standardize the development of programmers, this specification is specialized. Its fundamental purpose is to ensure that the program has a good, consistent structure, in order to improve the program's readability and maintainability, facilitate the process of testing, maintenance, upgrade, etc., and also cultivate programmers writing code normative .
1.2. Principle
The name reflects the meaning of the form.
1.3.
This specification applies to all companies that use MS .NET to develop tools. The programmer should be strictly prepared according to this specification. If the project has the special requirements, the project must also be reviewed, and the special requirements form a document. Save the attached file of the document.
Code specification
2.1. Project Specification
2.1.1. Each item, the document, according to the module, function must be stored on the project VSS, each project VSS must contain the following subdirectory:
2 Code: Source Catalog
2 SQL: Database script directory
2 Demodata: demo data directory
2 UserData: User Directory
2 Help: Help Document Directory
2 INSTALL: Installation Directory
2 Document: Document Catalog
2 Picture: Picture Directory
2 Templates: Template catalog
The subdirectories must be established in detailed uses in the subdirectory.
2.1.2. Without the primary directory of each project, there must be a project documentation, indicating some of the profiles and related specifications.
2.1.3. There must be a directory instruction file in each layer directory in the project directory, indicating the classification method and meaning of the layer directory and its subdirectories. At any time, when adding a directory, you must add the category of the new directory in the directory instructions in the same directory, and create the directory instruction file in this directory.
2.1.4. Engineering Code Specification:
2 Any project document (including dynamic link library project file) must be described in the form of an annotation, company copyright, engineering description, version description, creation date, authors, and subsequent updates.
2 Except for main modules, public function modules, and public data modules, all units under this project cannot be automatically created by the project. Once the new unit is added, the automatic Create statement must be removed in the project file.
2 The remaining code of the project document complies with the unit specifications and other code specifications of this document.
2.2. Source code file overall specification
2.2.1. The first part of each source code file must be explained in the form of the project in the form of the project, the company copyright.
2.2.2. In Using and Namespace, the project name, module name, module description, module version, creation date, author, update person, and TODO list are described in Using and NameSpace.
2.2.3. Before each class, the method, attribute, and events must have a corresponding annotation.
2.2.4. For classes with parameters, the meaning of the parameters will be described.
2.2.5. Overall style
2 Rehabilitation rules: Turn a "Tab" button at each stage.
2 Marked page Width: The program of each line should not be too long. It is best not to exceed 80 characters. If it exceeds, it is necessary to make a wrap.
2 Note Rules: If you only comment, use "//" as an comment. Multi-line comments, use "/ * ... * /" as an comment.
2 Dark line Use: You need to use the empty room with: blocking, class, method process function, method internal algorithm segmentation. The blank line can only be used in one line, and the extra blank line must be deleted. Example:
/ ************************************************** *******
project name
Copyright (C) 2000,2001 Company Name
*********************************************************** ****** /
Using system;
Using system.data;
/ ************************************************** *******
project name:
Module Name:
description:
version:
date:
Author:
Update:
Todo:
*********************************************************** ****** /
Namespace infocomm.dvap
{
///
/// Author:
/// Date:
/// Description:
/// summary>
Public class utilities, PUBLIC CLASS UTILITIES
{
///
/// Author:
/// Date:
/// Description:
/// summary>
///
Public Static String Connectionstring ()
{
Return "Connectionstring";
}
}
}
2.3. Internal specification of source code
2.3.1. Constant definition
2 The first prefix of all constants must be C, constant must be classified classified definition, if there are multiple topics, each subject must add a topic prefix. Between the prefix and the prefix, the prefix is used between _ segmentation.
2 Definitions of each constant alone, on the same line, must use "//" to explain the meaning of the constant.
2 The constant categorized by topic, the first line of each subject must use the "//" annotation meaning.
Example:
Const
{Topic 1}
C_ Theme Prefix 1_--- = ----; // Meaning
C_ Theme Prefix 1_--- = ----; // Meaning
C_ Theme Prefix 1_--- = ----; // Meaning
C_ Theme Prefix 1_--- = ----; // Meaning
{Topic 2}
C_ theme prefix 2 _--- = ----; // meaning
C_ theme prefix 2 _--- = ----; // meaning
C_ theme prefix 2 _--- = ----; // meaning
C_ theme prefix 2 _--- = ----; // meaning
2.3.2. Type definition
2.3.3. Variable definition
2 When the variable is defined, the variable name must have a clear meaning and cannot be used as a name.
2 variables are divided into global variables and local variables. The global variable needs to add "M_" prefix.
2 The first character of the local variable must be lowercase. Subsequent characters, case in size in the English syntax.
2 Each of the variables that need notes need to be annotated separately, and "//" commented in the end of the row.
2 Separation of variables in the same type and mean logically, the same type and the variables of the same type and the meaning logically are defined together.
2 Generally do not encourage global variables. When you need to use global variables, global variables must be limited to the required environment. 2 The global variable can be directly initialized to a certain value when defined.
2 Naming rules of the variable See the naming rule item behind this document.
2.3.4. Program main body
2 Events, process, function should be collected together according to the topic classification, and the first line of each subject starts this class with "/ * ... * /". The agreement classification method is as follows: The same control should be collected together, the function or process of the relationship between the event call or related to the event, the function, the process, the process, and the method should also Collect together unless the function is called multiple. The interior function called multiplely, the process should be detrimentally within the public process theme in the class. You can customize the categorization method, such as categorizing the function, but if the categorization method is different from this agreement, the classification method should be used before all topics.
2 Each event must be used in its code before its code, description, parameter meanings, creation time, author, update, and update time. In an event, a different meaning of different meanings or different topics intermarked, each algorithm or a topic starts with the purpose of "/ * ... * /" annotation algorithm or theme. The key algorithm should use the "//" annotation algorithm purpose in the end of the row. Event, the variable inside the method must be in accordance with the definition of variables.
2.3.3
The agreed variable area specification.
2 SQL statement writing rules: In the SQL statement, all SQL reserved words unified use of uppercase, all field names, and data table names all with lowercase, select, from, where, order, each clause requires each field. Or each condition or each associated is set separately. And indented alignment, and indent in two classes.
Note: Case ... When ... Then ... Else ... End statement is different.
2 Code uses the database field name in the code, unified written.
2.4. Grammar agreement
2.4.1. Grammatical miscellaneous
2 There must be one space before and after the operator.
2 In the starting parentheses and the latter character, and the end parentheses and the last characters do not have spaces.
2 Reserved words and keywords are always lowercase.
2.4.2. Process and functions
2 Conversion of the parametric mainly consider the register call rules.
2 The most common parameters should be used as the first parameter, follow the right right rows according to the frequency of use.
2 Enter parameters should be located before the output parameters.
2 large parameters of the range should be placed before the range of small parameters, such as SomeProc (String Country, String State, String City).
2 IDE automatically generated event handle, parameter order does not have to be convinced.
2 All constant parameters should be marked in a Const tag.
2 Unless it is indeed initialized before use, the internal variable of the routine should be initialized immediately at the entrance of the routine.
2.4.3. Statement specification
2 IF statement:
In the IF / THEN / ELSE statement, the most likely cases should be placed in the THEN clause, which may be smaller in the ELSE clause.
2 Do not nest 5 or more IF statements.
2 If the IF statement is too much, you can consider using the Switch statement.
2 If there are multiple conditions in the IF statement, the conditions should be neatly arranged from left to right from left to right from the fastest to the slowest computing difficulty.
2 Switch ... CASE statement:
In the Switch ... CASE statement, constants represent each case should be arranged in a number or alphabetical order.
The action statement corresponding to each case should be short and usually no more than 4-5 lines. If the action is too complex, the code should be placed in a separate process or function.
The Default clause of the Switch ... case statement is only used for default or error detection. Switch ... Case statement specification example:
Switch (n)
{
Case 1:
COST = 25;
Break;
Case 2:
COST = 25;
Goto Case 1;
Case 3:
COST = 50;
Goto Case 1;
DEFAULT:
Console.writeline ("Invalid Selection. Please select 1, 2, or 3.");
Break;
}
2 While statement:
The While statement executes a statement or a statement block until the specified expression is obtained. You can use Break to terminate the program.
All code initialized for the While loop should be in front of the WHILE port and do not be separated by unrelated statements.
Specifications for the While statement:
INT n = 1;
While (n <6)
{
Console.WriteLine ("Current Value of N IS {0}", N);
N ;
}
2 for statement:
The FOR loop repeats a statement or a statement until the specified expression is obtained.
If the number of cycles is determined, use the for statement to replace the While statement.
Specifications for the for statement:
For (INT i = 1; i <= 5; i )
Console.writeLine (i);
2 Try ... catch ... finally statement:
You need to perform some custom tasks when an exception occurs, only use of try ... catch.
If you want to activate the default abnormality in the Catch clause, you can trigger an exception again with throw.
Specifications for TRY statements:
Try
{
String s = null;
x.myfn (s);
}
// MOST SPECIFIC:
Catch (Argumentnullexception E)
{
Console.writeline ("{0} first exception caught.", E);
}
// Least Specific:
Catch (Exception E)
{
Console.writeline ("{0} second Exception Caught.", E);
}
2.5. Name Specification
2.5.1. Process, naming rules
2 Rechectures start with uppercase letters and should be capitalized at the first letter with different words.
2 The name of the routine should make sense and should try to use the Babble phrase.
2 Setting the routine name of the input parameter value should be prefixed by Set to its prefix, and the number of routines that get the value should be prefixed as GET.
2 The shape of the routine should express its use, as long as it may, the first letter of the shape name should be lowercase.
2 Automatically generated event handles, names, and parameters that are automatically generated by IDE.
2.5.2. Variable naming rules
2 The name of the variable should be able to express its use. Try not to abrupt, and use noun as a variable name.
2 Variable names should be used as a prefix, such as StrmasterSQL.
2 The loop control variable can be a single letter such as i, j, k, or a meaningful name can also be used.
2 The name of the Boolean variable must be clearly expressed in True and False's meaning.
2 The global variable of the project should be prefixed as G_. The global variable in the class should be prefixed as M_. 2.5.3. Type, class, object naming rule
2 Define the enumeration type should be used as a prefix before the name.
2 An array type name should express the use of the array, and the type name must add letter A to the prefix.
2 The name of the class must be the use of this class.
2 Private Data Data (Fields) naming rules are the same as other variables.
2 Method namings and procedures of class, the same name.
2 The property name of the 2 class should be noun, not a verb. The naming rules of the attribute are the same as the private data field of the class.
2 The event naming of the class should be in ON, Before, After as a prefix.
2.5.4. File naming specification
2 Project documents: Engineering documents should give meaningful names. You can take the full name of the project, or the uppercase of the start character of the word, or the abbreviation of each word. You can also naming a single word directly.
2 Form file: The name of the form file must be able to express the use of Form and have an FRM prefix.
2 Class file: The file name must be meaningful.
2.5.5. Component Naming Rules
2 Component naming standards and class naming standards are similar. Different are the iconic prefix they have three characters. Three characters as a prefix should be written.
2 Component instance naming rules: Component type prefix descriptive name.
2 The system namespace class prefix is as follows:
System.Web.ui.WebControls Namespace class
Class Abbreviation Description AdcreatedEventArgSentargs provides data for the Adcriptor control. Unable to inherit this class. AdrotatorRot displays published titles on the web page. BaseCompareValidatorBCVLD acts as an abstract base class for verification controls that perform type comparisons. BaseDataListBdlst is used as an abstract base class for a data list control, such as DataList and DataGrid. This type provides public methods and properties for all data list controls. BasevaliDatorBVLD is used as an abstract base class for verifying controls. BoundColumnbcol Binds the column type of the DataGrid control of the field in the data source. ButtonBTN displays normal button controls on the web page. The BUTTONCOLUMN BTNCOLDATAGRID control column type, which contains user-defined command buttons corresponding to each row in the column, such as add or remove. Calendarcal displays a single month, which makes users select the date and move to next month or last month. CalendardayCalday represents the date in the Calendar control. CheckBoxchk Displays the check box that allows users to select TRUE or FALSE Conditions. CheckBoxListchklst Creates a Multi-Selection check box group, which can be created by binding the control to the data source. CommandEventArgscmdenTargs provides data for Command events. CompareValidatorCMPVLD will compare the value of the user input to the input control with the value or constant value input to other input controls. CustomValidatorCustvld performs user-defined authentication for the input control. DataGridGRD data binding list control, which displays items from the data source in the table. The DataGrid control allows you to select and edit these items and sort them. DataGridColumngrdcol The base class for different column types of DataGrid controls. DataGridColumnCollectionGrdClClndataGridColumn exported column objects, which represent columns in the DataGrid control. Unable to inherit this class. DataGridCommandeventargsgrdcmndargs provides data for the following events for the DataGrid control: CancelCommand, DeleteCommand, EditCommand, ItemCommand, and UpdateCommand events. Unable to inherit this class. DataGridItemGrdItem represents a (line) in the DataGrid control. DataGridItemCollectionGrdItemcln represents a collection of DataGridItem objects in the DataGrid control. DataGriditeMeventargsGrditementargs provides data for the Itemcreated and ItemDatabase events for the DataGrid control. Unable to inherit this class. DataGridPageChangeDeventargsGrdpGeentargs provides data for the PageIndexchanged event for the DataGrid control. Unable to inherit this class. DataGridPagerstyleGrdpgeSty specifies the style of page navigation of the DataGrid control. This class cannot be inherited. DataGridSortCommandEventArgsGrdcmdenTargs provides data for the SortCommand event for the DataGrid control. Unable to inherit this class. DatakeyCollectionDKCLN represents a collection of key fields that contain each record in the data source. Unable to inherit this class. DataListDLST Displays the data bind list control using the item used to use the template. DataListCommandeventargsdlstcmandEventArgsdlstcmndargs provides data for the following events for the DataList control: CancelCommand, DeleteCommand, EditCommand, ItemMand, and UpdateCommand events. Unable to inherit this class.
DataListItemdlStItem represents items in the DataList control. DataListItemCollectionDLstCln represents a collection of DataListItem objects in the DataList control. Unable to inherit this class. DataListiteMeventargs provides data for the ItemCreated and ItemDatabase events for the DataList control. Unable to inherit this class. DayRendReventargsdayEntargs provides data for the DayRender event for the Calendar control. Unable to inherit this class. DROPDOWNLISTDDL represents the control that allows users to select an item from the drop-down list. The EditCommandColumnedTcmdColDataGrid control is a special column type that contains the edit command button for editing the data items in each row. FontInfofntinfo package text font properties. This class cannot be inherited. FontNamesConvertNCVTER converts a string containing the font name list to a string array containing individual names. It also performs reverse function. FontUnitConvertUCVTER converts FontUnit to an object with another data type. It also converts objects with another data type to FontUnit. HyperLinkhlnk displays controls for links to other web pages. The column type of the HyperLinkColumnhlnkColdAgrid control contains the hyperlinks of each item in the column. HyperLinkControlBuilderhlnkBUD interacts with the analyzer to generate the HyperLink control. ImageIMG displays an image on a web page. ImageButtonImgbtn displays an image and a control on the image to make a response. Labellbl indicates a tag control that displays text on the web page. LabelControlBuilderlBUD interacts with the analyzer to generate the Label control. LinkButtonlnkbtn displays the button control of the hyperlink style on the web page. LinkButtonControlBuilderLnkbtnBUD interacts with the analyzer to generate a linkbutton control. ListBoxlst represents a list of box controls that allow single or multiple selection. ListControlstcon is used as an abstract base class that defines all list type controls. ListitemlStItem represents the data item in the data binding list control. This class cannot be inherited. ListItemCollectionLstItemcol collection of ListItem objects in the list control. This class cannot be inherited. ListItemControlBuilderlStiteMBUD interacts with the analyzer to generate a ListItem control. LITERALLIT keeps the location where the static text is displayed on the web page. LiteralControlBuilderLitBud interacts with the analyzer to generate the Literal control. MonthchangeDeventargsmonentargs provides data for Calendar's VisibleMonthchanged events. Unable to inherit this class. PagedDataSourcecepGeds package the properties of the DataGrid control, which makes the control to perform paging. Unable to inherit this class. Panelpal represents controls for containers as other controls. PlaceHolderpla HLD Stores a container for dynamically adding server controls on the web page. PlaceHolderControlBuilderPlahldBUD interacts with the analyzer to generate a PlaceHolder control. RadiobuttonRBTN represents a radio button control. RadioButtonListRBTNLST represents a list control for encapsulating a set of radio button controls. RangeValidatorRgeVLD Checks if the value of the input control is within the specified value. RegularExpressionValidatorRgeExPVLD Verify that the value of the relevant input control matches the mode specified by the regular expression. RepeaterRep A data bind list control allows for a definition layout to be derived by repeatedly specified templates for each item displayed in the list.