Arnolyzer: adding clean-code static analysis to C# in VS2015

arnolyzer-logoArnolyzer is a Roslyn-based analyzer for Visual Studio 2015 that provides a set of compiler rules that encourage modern, functional-orientated, coding standards in C# 6. Pure functions; no inheritance; no global state; immutable data classes and variables; and short, concise sections of code.
Continue reading “Arnolyzer: adding clean-code static analysis to C# in VS2015”

Generic variance in C#, part 3 – Covariance

csharp_genericsIn part 2 of this series, we looked at contravariance, which is a special case of generic variance, for interfaces that only allow instances of T, for ISomeInterface<T>, to be passed in, either via method parameters or through property setters (though good code will not contain the latter, of course). It’s perhaps no surprise that covariance is the opposite. Only when ISomeInterface<T> allows instances of T to be passed out (either via method returns, or property getters), can that interface be covariant.
Continue reading “Generic variance in C#, part 3 — Covariance”

Posted in C#

Generic variance in C#, part 2 – Contravariance

csharp_genericsContravariance is perhaps the hardest of the three types of generic variance to understand (at least I found it so). This article hopefully takes the reader through two examples of its use to explain what it is, before showing how it’s used for real in the .NET Framework.

This is part 2 of a three part series on generic variance in C#. Part 1, covers invariance. The final part, covers covariance.
Continue reading “Generic variance in C#, part 2 — Contravariance”

Posted in C#

Generic variance in C#, part 1 – Invariance

csharp_genericsC#’s generic types are, by default, invariant. Special cases of covariant and contravariant can be defined though. So what does that previous gobbledygook even mean? Hopefully this three-part article will help explain these three terms, and why they even exist in the first place.

The second part of this series, looks at what is probably the least well understood of the three terms: contravariance. If you feel you understand the other two terms, feel free to jump straight to that part therefore. The third, and last, part, looks at covariance and finishes with a summary of the difference between the three. But first, we start at the beginning: invariance.
Continue reading “Generic variance in C#, part 1 — Invariance”

Posted in C#