System.Diagnostics.Contracts (compared to UnityEngine.Assertions)

Hi!

I would like to ask someone with experience of using C#'s standard Contracts in Unity:
a) How well does Ensures, Requires, Invariant, OldValue work in Unity?
b) Does the static analysis work as expected?
c) What is the support for this in release?
d) Is there some more significant performance hit?

I am asking because I only found one post of someone saying that something from Contracts does not work and not much else about it.

I know about the Unity’s own Assertion library, that it is built to work nicely with Unity’s ecosystem, that they are pretty light-weight and so on. But Contracts are much more powerful and I’d like to use them, so are there any big downsides compared to the Assertion library?

Background info: I’m currently working on a piece of code that I might consider releasing later as a library/asset. To that end I thought it would be good to use some Assertions or Contracts.

I have never used any of this newage chuff, never even looked it up in a Unity context, don’t even know if the Unity version of C# supports it.

It sounds like perhaps you are the person best-suited to do some experiments and let us all know what you find!

@svobodajak How did you find using the Contract class in Unity projects? I’m new to doing serious stuff in Unity and wondering about this, too.

EDIT: Rider prompted me to select how I want to do null checking… more options than I expected to evaluate!