Skip to content

Coding Style

Dirkster99 edited this page Jul 3, 2018 · 5 revisions

This page lists preferred coding in this project. These styles are no hard and solid rules but should generally be applied on new contributions to make the code readable for everyone interested.

General Restrictions

A coding style is only acceptable, if it is applicable in .Net version 4.5.2 or earlier and can be implemented below < C# version 7.

ICSharpCode.AvalonEdit

The project ICSharpCode.AvalonEdit is a feature added fork from icsharpcode/AvalonEdit.

This project should not be changed for coding styles unless you are fixing a critical bug or adding a feature. This project originates mainly from https://github.com/icsharpcode/AvalonEdit and should be updateable/merged with future developments from the original repo at a later point in time.

Expression Bodied Syntax

Sample for Style up to C# Version 6

  public int MyField
  {
    get { return _MyField; }
    set { _MyField = value; }
  }

Sample for Style in C# Version 7 and later

public int MyField{ get => _MyField; set => _MyField = value; }

Please use the C# Version 6.0 style in this project.

Private Fields and Properties

The names of properties should start with upper case and can contain CamelCase Naming convention:

public int MyField{ get => _MyField; set => _MyField = value; }

A backing private field that is used in a property should have the same name but start with an underscore letter '_'.

Usage of this Keyword

The this keyword should be used only in exceptional cases. For example, when it is necessary to distinguish this from base, and so forth.

Sample for old Style

if (_ActiveDocument is MiniUmlViewModel vm)
{
  return vm.DocumentMiniUML as MiniUML.Model.ViewModels.Document.AbstractDocumentViewModel;
}

Sample for current Style

if (_ActiveDocument is MiniUmlViewModel)
{
  MiniUmlViewModel vm = _ActiveDocument as MiniUmlViewModel;

  // would be best to wrap a null if check here to ensure as was able to cast
  return vm.DocumentMiniUML as MiniUML.Model.ViewModels.Document.AbstractDocumentViewModel;
}

More Details: https://github.com/Dirkster99/Edi/issues/22

Tabs and Spaces

The following Visual Studio settings for Tabs & Spaces are preferred:

  • Indenting: Smart
  • Tab Size: 4
  • Indent Size: 4
  • Insert Spaces (checked)

Usage of using statements

The using statements in this projects are generally used inside namespace not in front of a namespace. The recommended style is this:

namespace Edi.Apps.Behaviors
{
  using System.Windows.Input;
  using System.Windows;
  
  public static class ActivatedCommand
  {
  }
}

formating code like this has advantages in larger projects like this.