Coding Conventions
Coding Conventions
Pascal Case
| Sr No | Conventions |
|---|---|
| 1 | Method Name Example : OrderIndex() |
| 2 | Class Name Example : AccountMst |
| 3 | Property Name Example : ItemName |
Camel Case
| Sr No | Conventions |
|---|---|
| 1 | Variables Example : companyData |
| 2 | Temporary Field Name Instantiated should start with _ |
| 3 | Parameters Example : accountType |
Razor Page
| Sr No | Conventions |
|---|---|
| 1 | Page directives should always be declared in Small Case ℹ️ Example : invoicecreate, ordermodify |
| 2 | Razor page name and method names in the razor page should not be the same. |
| 3 | Similarly the razor page name and the model class name should not be the same otherwise it will go into an infinite loop. |
| 4 | Method name and property name should not be same. |
Common Conventions
| Sr No | Conventions |
|---|---|
| 1 | Controller call in service page should be in small case Example : api/invoice/invoicedelete |
| 2 | Async and Await should be removed from controller and repository methods where we are updating(Modify), inserting(Create) or deleting(Delete) the records. ℹ️ Also remove async and await from methods which are only called inside the above methods. For example : Inside the OrderCreate() method we are calling GetMaxCount() method in the controller. The GetMaxCount() is not called anywhere else. So we can remove async await from this method also. If we want to call a async method inside non async method then use .Result with the asyn method call. |
| 3 | If there are many if conditions for the same column then use else if. |
| 4 | After every method is completed leave 1 line. |
| 5 | While reviewing the code, do not make any changes in the code like for example leaving lines or removing lines. |
| 6 | Whenever any changes has to be made comment the previous code(in which changes has to be made) and then add one more comment line with your name, current date and description, copy the code and then make required changes in the copied code. This is do be done only when you are making changes for branch which is already merged with master or which already exists. |
| 7 | using in Repository should not be declared as ℹ️ using (var connection = _DapperContext.SetClientConnection(dbname))
{
connection.Execute(query, new { id });
} Instead declare it as ℹ️ using var connection = _DapperContext.SetClientConnection(dbname);
var data = connection.Execute(query, new { id }); |
| 8 | Instead of doing + for concatination use $ sign |
| 9 | If there is column like status then for inserting or updating O or C declare a property StatusCode & for showing Open or Close in details or index page use StatusName property. |
| 10 | In Reports number formatting will be in this format ##0.00;[Red](##0.00) (Note : Decimals will change as per column) |
- For text wrap and width we will you below given for each syntax instead of old syntax
/// Old Syntax
workSheet.Column(7).Width = 40;
workSheet.Column(7).Style.Alignment.WrapText = true;
workSheet.Column(8).Width = 40;
workSheet.Column(8).Style.Alignment.WrapText = true;
workSheet.Column(31).Width = 40;
workSheet.Column(31).Style.Alignment.WrapText = true;
workSheet.Column(35).Width = 40;
workSheet.Column(35).Style.Alignment.WrapText = true;
/// New Syntax
int[] columnsToFormat = [7, 8, 31, 35 ];
foreach (int columnIndex in columnsToFormat)
{
workSheet.Column(columnIndex).Width = 40;
workSheet.Column(columnIndex).Style.Alignment.WrapText = true;
}SQL Conventions
| Sr No | Conventions |
|---|---|
| 1 | Keywords should be in upper case Example : MAX,SELECT,WHERE,ON etc |
| 2 | SQL Query should be readable i.e it should not scroll to right side |
| 3 | If we want to make changes between a query then instead of commenting the whole query use ‘- -’ to comment the line. |
| 4 | Whenever writing sql query take JOIN, WHERE to new line Instead of writing like : ℹ️ SELECT * FROM T LEFT JOIN A ON T.id = A.id WHERE T.id=’@id’ ; Write like this : ℹ️ SELECT * FROM T
LEFT JOIN A ON T.id = A.id
WHERE T.id=’@id’ ; |
| 5 | In the queries instead of + use CONCAT. |
| 6 | Instead of using Asterisk ( * ) in SELECT queries take only those columns which need to be used. |
| 7 | Instead of using inner queries use WITH query. |