Boolean Equivalent For `System.Numerics.IBitwiseOperators` Interface

63 views Asked by At

Included in the System.Numerics library is the relatively new interface IBitwiseOperators<TSelf, TOther, TResult>. It contains functionality for bitwise manipulations on integers (e.g. AND, OR, XOR, and NOT).

However, booleans do not implement it. What is the equivalent of this interface for booleans?

I know this is kind of a newbie question, but I can't find the answer anywhere on the internet. I checked the Microsoft documentation, but didn't really know what to look for.

Any help please?

I am using this to create a generic function to assist in the creation of delegates which will be used on dynamically-typed values.

Effectively, one part of my code is this function:

T Not<T>(T Value) where T : ? => !Value;

Which is later assigned to a delegate:

Func<bool, bool> d = Not<bool>;

Which is later applied to a variable:

x = d(x);

Which function d will be set to is determined at runtime; the not operator is only one of the potential functions.

I use the interface as a type constraint so that the function doesn't throw a runtime error.

0

There are 0 answers