Below are some of the things you (as the pull-requestor) needs to consider when doing a code change on the project. We hope that you will familiarize the entire contents before contributing, and thank you for that!
Please be noted that this coding standard is not a strict compliance for you to make a PR towards us. Though, your code will be reviewed and evaluated thoroughly. Further collaborations may be done between you (the contributor) and us if there are any clarrifications before merging.
Disclaimer: Some of the written standards on this page are the preferences of the author itself. We are listening to any comments, therefore please do let us know if you think we need to adjust the standards.
Like this:
public class QueryField
{
...
}
Not like this:
public class queryField
{
...
}
Like this:
public IEnumerable<QueryField> QueryFields { get; set; }
Not like this:
public IEnumerable<QueryField> queryFields { get; set; }
Like this:
public string ConnectionString { get; set; }
Not like this:
private string m_propertyName;
public string propertyName
{
get { return m_propertyName; }
set { m_propertyName = value; }
}
This is not the case always. However, please always consider the usage of direct assignment first (if feasible) before doing any other implementation approach.
public string ConnectionString => DbRepository.ConnectionString;
Like this:
var field = new QueryField("Name", "Value");
Not like this:
QueryField field = new QueryField("Name", "Value");
Like this:
var propertyIndex = 0;
Not like this:
var propertyindex = 0;
var ProperyIndex = 0;
Like this:
var propertiesCount = properties.Count();
Not like this:
var x = properties.Count();
Like this:
private IDbConnection activeConnection;
Not like this:
private IDbConnection _activeConnection;
Please avoid using the Linq ForEach()
method.
Like this:
foreach(var queryField in queryFields)
{
...
}
Not like this:
queryFields.ForEach(queryField =>
{
...
});
Reason: The author preferred the lowest level implementation as always for performance purposes.
Like this:
if (true)
{
Process();
}
Not like this:
if (true)
Process();
if (true) Process();
This must be done in all implementations.
- Methods
- Properties
- Classes
- Interfaces
- Enumerations
Like this:
var tableName = string.Concat("[dbo].[", entityName, "]");
Not like this:
var tableName = "[dbo].[" + entityName + "]";
Reason: The author preferred the lowest level implementation as always for performance purposes.
Like this:
var tableName = string.Concat("[dbo].[", entityName, "]");
Not like this:
var tableName = $"[dbo].[{entityName}]";
Reason: String interpolation is slow and is not efficient.
Like this:
var entities = QueryAll<T>();
Not like this:
var entities = this.QueryAll<T>();
Like this:
var childQueryFields = queryGroup.QueryFields.AsList();
Not like this:
var childQueryFields = queryGroup.QueryFields.ToList();
The methods must only contains few lines of code. We prefer to have it maximum of 25 lines of code per method.
Note: It is not always the case. This is not a strict compliance.
This is an author's preference. Always use a new-lined arguments.
Like this:
internal static async Task<int> MergeAllAsyncInternalBase<TEntity>(this IDbConnection connection,
string tableName,
IEnumerable<TEntity> entities,
IEnumerable<Field> qualifiers,
int batchSize,
IEnumerable<Field> fields,
int? commandTimeout = null,
IDbTransaction transaction = null,
ITrace trace = null,
IStatementBuilder statementBuilder = null,
bool skipIdentityCheck = false)
where TEntity : class
{
...
}
Not like this:
internal static async Task<int> MergeAllAsyncInternalBase<TEntity>(this IDbConnection connection, string tableName, IEnumerable<TEntity> entities, IEnumerable<Field> qualifiers, int batchSize, IEnumerable<Field> fields, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, IStatementBuilder statementBuilder = null, bool skipIdentityCheck = false) where TEntity : class
{
...
}
The regions are rich in RepoDb.
Like this:
#region Properties
public string ConnectionString => DbRepository.ConnectionString;
#endregion
Like this:
#region Static Properties
public static IDbConnection ActiveConnection { get; private set; }
#endregion
Like this:
#region Privates
public int? m_hashCode = null;
#endregion
Like this:
#region Statics/Privates
public static IDbConnection m_activeConnection = null;
#endregion
Like this:
#region Constructors
public QueryGroup(QueryField queryField) :
this(queryField?.AsEnumerable(),
null,
Conjunction.And,
false)
{ }
public QueryGroup(QueryGroup queryGroup) :
this(null,
queryGroup?.AsEnumerable(),
Conjunction.And,
false)
{ }
#endregion
#region Methods
public void Fix()
{
...
}
#endregion
#region Methods
public static IEnumerable<Field> Parse<T>(T instance)
{
...
}
#endregion