clowd / Clowd.Squirrel

Quick and easy installer and automatic updates for cross-platform dotnet applications
427 stars 39 forks source link

Code contracts are deprecated and should be replaced #185

Closed KennyTK closed 8 months ago

KennyTK commented 10 months ago

Summary:

What are code contracts? https://learn.microsoft.com/en-us/dotnet/framework/debug-trace-profile/code-contracts

Solutions:

  1. Nullability supported since C# 7.0. Replace Contract.Requires(variable != null); with ArgumentNullException.ThrowIfNull
  2. system.diagnostics.codeanalysis supported in NET core. Compatible with framework but feature essentially not available. Use Postconditions: MaybeNull and NotNull
  3. Just remove them because they're clutter.

Further reading:

dotnet runtime 23869 stackexchange 47108 dotnet roslyn-analyzers 3134 nullable-analysis

caesay commented 8 months ago

I remove these and replace with throwing exceptions when I come across them.