Cleaner constructors with throw expressions in C# 7

When creating classes it’s important to create constructors that don’t allow creating objects in an invalid state. I blogged about this in the past (in polish – Czy programiści .NET zapomnieli o konstruktorach?). To prevent this we add validations in constructors. One of the most common is validating if object passed to constructor isn’t null. This is boooring code that you just have to type in (Resharper helps here) and before C# 7 and throw expressions it introduces it was taking a lot of space in constructor.

Czytaj dalej »