Based on .Net Core guildlines (https://github.com/dotnet/corefx/blob/master/Documentation/coding-guidelines/coding-style.md)
- We use Allman style braces, where each brace begins on a new line. A single line statement block can go without braces but the block must be properly indented on its own line and must not be nested in other statement blocks that use braces.
while (x == y)
{
something();
somethingelse();
}
finalthing();- We use four spaces of indentation.
- We use
m_camelCasefor internal and private fields and usereadonlywhere possible. Prefix internal and private instance fields withm_, static fields withs_. When used on static fields,readonlyshould come afterstatic(e.g.static readonlynotreadonly static). Public fields should be used sparingly and should use PascalCasing with no prefix when used. - We use
UPPER_CASEfor constants. - We avoid
this.unless absolutely necessary. - We always specify the visibility, even if it's the default (e.g.
private string m_foonotstring m_foo). Visibility should be the first modifier (e.g.public abstractnotabstract public). - Namespace imports should be specified at the top of the file, outside of
namespacedeclarations. - Avoid more than one empty line at any time. For example, do not have two blank lines between members of a type.
- Avoid spurious free spaces.
For example avoid
if (someVar == 0)..., where the dots mark the spurious free spaces. - We only use
varwhen it's obvious what the variable type is (e.g.var stream = new FileStream(...)notvar stream = OpenStandardInput()). - We use language keywords instead of BCL types (e.g.
int, string, floatinstead ofInt32, String, Single, etc) for both type references as well as method calls (e.g.int.Parseinstead ofInt32.Parse) - We use
nameof(...)instead of"..."whenever possible and relevant. - Fields should be specified at the top within type declarations.
- When including non-ASCII characters in the source code use Unicode escape sequences (\uXXXX) instead of literal characters. Literal non-ASCII characters occasionally get garbled by a tool or editor.
- When using a single-statement if, we follow these conventions:
- Never use single-line form (for example:
if (source == null) throw new ArgumentNullException("source");) - Using braces is always accepted, and required if any block of an
if/else if/.../elsecompound statement uses braces or if a single statement body spans multiple lines. - Braces may be omitted only if the body of every block associated with an
if/else if/.../elsecompound statement is placed on a single line.
- Never use single-line form (for example:
An EditorConfig file (.editorconfig) has been provided at the root of the repository
ObservableLinkedList1.cs:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using Microsoft.Win32;
namespace System.Collections.Generic
{
public partial class ObservableLinkedList<T> : INotifyCollectionChanged, INotifyPropertyChanged
{
private ObservableLinkedListNode<T> _head;
private int _count;
public ObservableLinkedList(IEnumerable<T> items)
{
if (items == null)
throw new ArgumentNullException(nameof(items));
foreach (T item in items)
{
AddLast(item);
}
}
public event NotifyCollectionChangedEventHandler CollectionChanged;
public int Count
{
get { return _count; }
}
public ObservableLinkedListNode AddLast(T value)
{
var newNode = new LinkedListNode<T>(this, value);
InsertNodeBefore(_head, node);
}
protected virtual void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
{
NotifyCollectionChangedEventHandler handler = CollectionChanged;
if (handler != null)
{
handler(this, e);
}
}
private void InsertNodeBefore(LinkedListNode<T> node, LinkedListNode<T> newNode)
{
...
}
...
}
}ObservableLinkedList1.ObservableLinkedListNode.cs:
using System;
namespace System.Collections.Generics
{
partial class ObservableLinkedList<T>
{
public class ObservableLinkedListNode
{
private readonly ObservableLinkedList<T> _parent;
private readonly T _value;
internal ObservableLinkedListNode(ObservableLinkedList<T> parent, T value)
{
Debug.Assert(parent != null);
_parent = parent;
_value = value;
}
public T Value
{
get { return _value; }
}
}
...
}
}