Coding Conventions

Coding Conventions

Coding Conventions

Pascal Case
Sr NoConventions
1Method Name Example : OrderIndex()
2Class Name Example : AccountMst
3Property Name Example : ItemName
Camel Case
Sr NoConventions
1Variables Example : companyData
2Temporary Field Name Instantiated should start with _
3Parameters Example : accountType
Razor Page
Sr NoConventions
1Page directives should always be declared in Small Case
ℹ️
Example : invoicecreate, ordermodify
2Razor page name and method names in the razor page should not be the same.
3Similarly the razor page name and the model class name should not be the same otherwise it will go into an infinite loop.
4Method name and property name should not be same.
Common Conventions
Sr NoConventions
1Controller call in service page should be in small case Example : api/invoice/invoicedelete
2Async 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.
3If there are many if conditions for the same column then use else if.
4After every method is completed leave 1 line.
5While reviewing the code, do not make any changes in the code like for example leaving lines or removing lines.
6Whenever 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.
7using 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 });
8Instead of doing + for concatination use $ sign
9If 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.
10In 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 NoConventions
1Keywords should be in upper case Example : MAX,SELECT,WHERE,ON etc
2SQL Query should be readable i.e it should not scroll to right side
3If we want to make changes between a query then instead of commenting the whole query use ‘- -’ to comment the line.
4Whenever 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’ ;
5In the queries instead of + use CONCAT.
6Instead of using Asterisk ( * ) in SELECT queries take only those columns which need to be used.
7Instead of using inner queries use WITH query.