Agate C# Code Conventions
Naming Conventions
General Naming Conventions - Framework Design Guidelines
- Pascal Case
public class ClassNameUsingPascalCase
{ ... }
public interface IClassNameUsingPascalCase
{ ... }
public function DoSomething() //public function using pascal case
{ ... }
public int AlsoUsingPascalCase { get; set; } // public properties using pascal case
public enum EnumPascalCase
{ ... }
- Camel Case
private function usingCamelCase() { ... }
private function usingCameCase(string paramsAlsoCamelCase, int camelCase) { ... }
string privateVariable = "private variable also using camel case";
Code References
✅ Do
- Ordered Alphabetically
using Agate.Backend.Game.Core.ProjectCore.Errors;
using Agate.Backend.Game.Core.ProjectCore.Extensions;
using Agate.YourProjectName.Game.Common.Constants;
using Agate.YourProjectName.Identity.Api.Repositories;
using Serilog;
using System;
using System.Collections.Generic;
❌ Don’t
- Random ordered
using System;
using Agate.Backend.Game.Core.ProjectCore.Extensions;
using Agate.YourProjectName.Identity.Api.Repositories;
using Agate.YourProjectName.Game.Common.Constants;
using Serilog;
using System.Collections.Generic;
using Agate.Backend.Game.Core.ProjectCore.Errors;
Add _
(underscore) prefix on Private / Read Only Properties
✅ Do
- Using this convention :
private readonly string **_privateString**;
❌ Don’t
- Using this convention :
private readonly string **Private_String**;
Catching & Throwing Errors
✅ Do
- Throwing expected errors
public bool SomeFunction(string param)
{
if (string.IsNullOrEmpty(param))
{
_logger.LogError($"Param is null or empty");
throw new NullReferenceException($"{nameof(param)} is null");
}
return true;
}
❌ Don’t
- Returns expected errors as returned value
public (bool, Error) SomeFunction(string param)
{
if (string.IsNullOrEmpty(param))
{
_logger.AgateLogError($"Param is null or empty");
return (false, ErrorUtil.LoginInvalid);
}
return (true, null);
}
Defining Class
✅ Do
- One class per file, example
ExampleClassOne.cs
&ExampleClassTwo.cs
namespace Agate.YourProjectName.Identity.Api.Example
{
public class ExampleClassOne
{ ... }
}
namespace Agate.YourProjectName.Identity.Api.Example
{
public class ExampleClassTwo
{ ... }
}
- Class category name in class suffix
namespace Agate.YourProjectName.Identity.Api.Data
{
public class AuthMessageData
{ ... }
}
❌ Don’t
- Multiple class in one file,
ExampleClass.cs
namespace Agate.YourProjectName.Identity.Api.Example
{
public class ExampleClassOne
{ ... }
public class ExampleClassTwo
{ ... }
}
- Class category not included
namespace Agate.YourProjectName.Identity.Api.Data
{
public class AuthMessage
{ ... }
}
No Comments