← Back to Home

In this Article:

πŸ€” Notice something is missing or not working? β†’ Please contact Zoel (zoelbastianbach@agate.id) on Ms. Teams!

https://embed.notionlytics.com/s/VjIxdGJWWmtiRzAzU1c1VVVsbERZMFJ1TURFPQ==

Overview


Consistency is the key to maintainable code. This statement is most true for naming your projects, source files, and identifiers including Fields, Variables, Properties, Methods, Parameters, Classes, Interfaces, and Namespaces.

The table below is the summary/TL;DR version of the naming conventions in this article:

Naming Overview

General Naming Convention


Naming Usage


Namespace

See Namespace Standard

Source Files

Capitalization: PascalCase

βœ… ALWAYS match class name and file name.

❌ AVOID including more than one class, enum (global), or delegate (global) per file.

Use a descriptive file name when containing multiple class, enum (global), or delegate (global).

MyClass.cs
public class MyClass {…}

Class or Struct

Capitalization: PascalCase

Use a noun or noun phrase for class name. Add an appropriate class-suffix when sub-classing another type when possible.

private class MyClass {…} 
internal class SpecializedAttribute : Attribute {…} 
public class CustomerCollection : CollectionBase {…} 
public class CustomEventArgs : EventArgs {…} 
private struct GameSettings {…}

Interface

Capitalization: PascalCase

βœ… ALWAYS prefix interface name with capital β€œI”

interface ICreature {…}
interface IWeapon

Generic Class

Capitalization: PascalCase

βœ… ALWAYS use a single capital letter, such as T or K.

public class FifoStack<T> {
		public void Push(T obj) {…}
		public T Pop() {…}
}

Method

Capitalization: PascalCase

βœ… TRY to use a Verb or Verb-Object pair.

public void Execute() {…}
private string GetAssemblyVersion(Assembly target) {…}

Property

Capitalization: PascalCase

Property name should represent the entity it returns. Never prefix property names with β€œGet” or β€œSet”.

// DO NOT do this:
public string GetName { 
		get{…}
}

// DO this instead:
public string Name { 
		get{…} 
		set{…} 
}

Field (Public, Protected, or Internal)

Capitalization: PascalCase

❌ AVOID using non-private Fields! Use Properties instead.

public string Name;
protected IList InnerList;

Field (Private)

Capitalization: camelCase

Prefix with a single underscore ( _ ) character.

private string _name;

Constant or Static Field

Treat like a Field. Choose appropriate Field access-modifier above.

Enum

Capitalization: PascalCase (both the Type and the Options).

Add the FlagsAttribute to bit-mask multiple options.

public enum CustomerTypes
{
		Consumer,
		Commercial
}

Delegate or Event

Treat as a Field. Choose appropriate Field access-modifier above.

public event EventHandler LoadPlugin;