Skip to the content.

C #

The following readme describes the coding conventions especially for C#.

Visual Studio Settings can be found here

Generally speaking we do follow the official Microsoft standard, if any definitions below clash with their standard our convention is to be preferred.

If something is generally off please refer to Johann or Rainer; One of them will provide clarification and update these conventions

Naming

Indentation

Refer to Microsoft naming convention for further details

Inline Comments

We use the XML notation for comments, refer to this example. It also has a tag reference.

namespace Aist.Dictionary.Core 
{
    /// <summary>
    /// This class decides where to put an item in the Dictionary.
    /// </summary>
    /// <typeparam name="T">The type of the domain class this Service can handle, e.g. Book</typeparam>
    public class DictionaryService<T>
    { }
}

New Lines and Blocks

As per Microsoft Coding Guidelines each brace gets a new line

Unit Tests

Example

using AIST.SimilarityMetrics;
using System;
using Xunit;

namespace AIST.Dictionary.Test
{
    public class TestJaroSimilarety
    {

        [Fact]
        public void EqualStrings()
        {
            //given
            ISimilarityMetric similarityMetric = new JaroSimilarity();

            //when
            double actual = similarityMetric.CalculateSimilarity("Wasser", "Wasser");

            //then
            Assert.Equal(1, actual);
        }
    }
}

Extended Coding Guidelines

If you ever need some distraction from your actual work tasks, https://csharpcodingguidelines.com/ are definitely worth a read. They go beyond the usual naming and formatting rules, listing suggestions for class and member design, mainainability and performance guidelines, error handling, and a few others.

The guidelines are also available in PDF format and in a short Cheatsheet version through the corresponding GitHub Repository.

In case you want to enforce these suggestions / guidelines more strictly, you can add the provided Roslyn Analyzers to your project through NuGet. A full list of included rules can be found here.