0

I don't solve a particular problem, but experimenting with C# in general.

Currently, I'm wondering why for many primitive types (DateTime, decimal, float, etc.) there are operator methods (==, >, +, etc.) that are visible via reflection, but there are no such operators for bool and int types.

I receive operators this way: How to call custom operator with Reflection

Is there an option to invoke such operators in runtime in the case of these types (int, bool)?

I am specifically interested in comparison operators (>, >=, ==,, etc.), but I think the answer will be the same for all operators...

Serhii
  • 430
  • 3
  • 18
  • 2
    The operators you want are a single opcode each. – Theraot Sep 16 '21 at 11:07
  • 2
    I believe you _can_ do this in .NET 6, with generic math and stuff. `System.Int32` in .NET 6 declares an explicit interface implementation of `IComparisonOperators`, which includes the operators that you want to get. But before .NET 6, there is no `<` operator or `>` operator declared on `System.Int32`, so you are literally trying to get something which doesn't exist. – Sweeper Sep 16 '21 at 11:18
  • See [the source](https://source.dot.net/#System.Private.CoreLib/Int32.cs,365). – Sweeper Sep 16 '21 at 11:19

0 Answers0