dbolin / Apex.Analyzers

Roslyn powered analyzers for C# to support convention defined architecture
MIT License
15 stars 2 forks source link
analyzer architecture csharp immutable roslyn roslyn-analyzer roslyn-analyzers type

Apex.Analyzers

Roslyn powered analyzers for C# to support convention defined architecture

Immutable Types

Build Status

Nuget Package

Provides an ImmutableAttribute type which can be applied to classes, structs, and interfaces. The analyzer ensures that the following rules hold for types marked with the attribute.

ID Severity Rule Code Fix
IMM001 Error Fields in an immutable type must be readonly Yes
IMM002 Error Auto properties in an immutable type must not define a set method Yes
IMM003 Error Types of fields in an immutable type must be immutable No
IMM004 Error Types of auto properties in an immutable type must be immutable No
IMM005 Warning 'This' should not be passed out of the constructor of an immutable type No
IMM006 Error The base type of an immutable type must be 'object' or immutable No
IMM007 Error Types derived from an immutable type must be immutable No
IMM008 Warning 'This' should not be passed out of an init only property method of an immutable type No

Whitelisting types via additional files

The immutable types analyzer allows specifying types to be whitelisted in an Additional File.

The name of the additional file is "ImmutableTypes.txt" and the format of the file is one namespace qualified type name per line. For example:

System.Xml.Linq.XName
System.Func`1