C# Coding Convention
====================
1. General Naming Convention
-> If more than one word is combined then you can follow either of below conventions.
- Pascal Case: Capitalize first letter of each words. For eg: StudentService, FirstName, CapitalCityOfNepal, etc.
- camel Case: first word is all lowe case and Rest follow pascal case. For eg: studentService, firstName, capitalCityOfNepal, etc.
-> This is valid for all the naming i.e. variable, field, property, method, class, etc.
-> If More than two letters acronym or abbreviation then follow pascal case otherwise make all capitals.
-> For eg:
i) PI constant
const float PI = 3.145f; -> Acronym PI is exactly two letters acronym so, all letters is capitals.
ii) API controller -> This should be 'StudentApiController' as API is more than 2 letters i.e. 3 letters acronym so, Pascal Case.
2. Naming Of Class
i) Pascal Case
ii) Service Name
-> Create Separate folder called 'Services'.
-> Append Service Name with the 'Service' Keyword.
-> For eg: Creating Service for Student. Then, name of Service should be 'StudentService.cs'.
iii) Api Controller Name
-> Create Separate folder called 'ApiController' or 'Api'.
-> Append Api Controller name with 'ApiController' keyword.
-> For eg: Creating Api Controller for Student. Then, name of Api Controller should be 'StudentApiController.cs'.
iv) Controller Name
-> Create Separate folder called 'Controller'.
-> Append Controller name with 'Controller' keyword.
-> For eg: Creating Controller for Student. Then, name of Controller should be 'StudentController.cs'.
v) Provider Name
-> Create Separate folder called 'Provider'.
-> Append Provider name with 'Provider' keyword.
-> For eg: Creating Provider for Student. Then, name of Provider should be 'StudentProvider.cs'.
3) Naming of Method
-> Pascal Case
-> It should be prepended by Verbs.
-> Should be meaningful and short. Exceptionally, can be longer too.
-> Commonly used are Get, Display, Delete, Update, etc.
-> For eg: GetStudent(), DeleteStudent(), etc.
4) Naming of Property
-> Pascal Case
-> It should be noun or name or depends on the type of property.
-> Should be meaningful and short. Exceptionally, can be longer too.
-> For eg:
public string FirstName { get; set; }, public string Email { get; set; } etc.
5) Naming Of Fields
i) Inside Class
-> It should be prepended with the underscore '_'.
-> Should be meaningful and short. Exceptionally, can be longer too.
-> For eg:
private readonly StudentService _studentService = null;
private const float PI = 3.14f;
ii) Inside Method
-> Camel Case
-> Should be meaningful and short. Exceptionally, can be longer too.
-> For eg:
float temp = 0f;
6) Naming of variables/ arguments/ parameters
-> Camel Case
==============================
Gitlab/Github Uses
==============================
1. Feature Branch
-> Should be for all the new features coming to the project.
-> For eg: Report feature is requested by clients for the Student Attendance. Then name should be 'feature/StudentAttendanceReport' or 'feature/student_attendance_report'.
2. BugFix Branch
-> Should be for all the issues comming to existing features of the project.
-> For eg: Report Bug is requested by clients for the Student Attendance. Then name should be 'bugfix/StudentAttendanceReport' or 'bugfix/student_attendance_report'.
====================
1. General Naming Convention
-> If more than one word is combined then you can follow either of below conventions.
- Pascal Case: Capitalize first letter of each words. For eg: StudentService, FirstName, CapitalCityOfNepal, etc.
- camel Case: first word is all lowe case and Rest follow pascal case. For eg: studentService, firstName, capitalCityOfNepal, etc.
-> This is valid for all the naming i.e. variable, field, property, method, class, etc.
-> If More than two letters acronym or abbreviation then follow pascal case otherwise make all capitals.
-> For eg:
i) PI constant
const float PI = 3.145f; -> Acronym PI is exactly two letters acronym so, all letters is capitals.
ii) API controller -> This should be 'StudentApiController' as API is more than 2 letters i.e. 3 letters acronym so, Pascal Case.
2. Naming Of Class
i) Pascal Case
ii) Service Name
-> Create Separate folder called 'Services'.
-> Append Service Name with the 'Service' Keyword.
-> For eg: Creating Service for Student. Then, name of Service should be 'StudentService.cs'.
iii) Api Controller Name
-> Create Separate folder called 'ApiController' or 'Api'.
-> Append Api Controller name with 'ApiController' keyword.
-> For eg: Creating Api Controller for Student. Then, name of Api Controller should be 'StudentApiController.cs'.
iv) Controller Name
-> Create Separate folder called 'Controller'.
-> Append Controller name with 'Controller' keyword.
-> For eg: Creating Controller for Student. Then, name of Controller should be 'StudentController.cs'.
v) Provider Name
-> Create Separate folder called 'Provider'.
-> Append Provider name with 'Provider' keyword.
-> For eg: Creating Provider for Student. Then, name of Provider should be 'StudentProvider.cs'.
3) Naming of Method
-> Pascal Case
-> It should be prepended by Verbs.
-> Should be meaningful and short. Exceptionally, can be longer too.
-> Commonly used are Get, Display, Delete, Update, etc.
-> For eg: GetStudent(), DeleteStudent(), etc.
4) Naming of Property
-> Pascal Case
-> It should be noun or name or depends on the type of property.
-> Should be meaningful and short. Exceptionally, can be longer too.
-> For eg:
public string FirstName { get; set; }, public string Email { get; set; } etc.
5) Naming Of Fields
i) Inside Class
-> It should be prepended with the underscore '_'.
-> Should be meaningful and short. Exceptionally, can be longer too.
-> For eg:
private readonly StudentService _studentService = null;
private const float PI = 3.14f;
ii) Inside Method
-> Camel Case
-> Should be meaningful and short. Exceptionally, can be longer too.
-> For eg:
float temp = 0f;
6) Naming of variables/ arguments/ parameters
-> Camel Case
==============================
Gitlab/Github Uses
==============================
1. Feature Branch
-> Should be for all the new features coming to the project.
-> For eg: Report feature is requested by clients for the Student Attendance. Then name should be 'feature/StudentAttendanceReport' or 'feature/student_attendance_report'.
2. BugFix Branch
-> Should be for all the issues comming to existing features of the project.
-> For eg: Report Bug is requested by clients for the Student Attendance. Then name should be 'bugfix/StudentAttendanceReport' or 'bugfix/student_attendance_report'.
Comments
Post a Comment