Using the new INumber interface to determine if an object is a number without having the generic arg
With .net7 we now have the INumber<TSelf> interface which is pretty cool, and I thought I found a place where I might be able to use it for the first time. However, I am running into some trouble.
I am wondering if there is any way to know if some ‘object’ is a number and return the ‘One’ abstract static property from the INumber<TSelf> interface it would implement. The issue is I do not have a generic argument to plug in for TSelf, and I cannot add one in this case since the method I am working on is an override of a method outside of my control and it does not have a T generic argument.
Here is a cut-down example as a x-unit test of what I am doing and what I have tried.
Unfortunately, with INumber<TSelf> being so new there is not a lot of information about it online so before I give up, I figured I would see if anyone here knows how to achieve this.
I am wondering if there is any way to know if some ‘object’ is a number and return the ‘One’ abstract static property from the INumber<TSelf> interface it would implement. The issue is I do not have a generic argument to plug in for TSelf, and I cannot add one in this case since the method I am working on is an override of a method outside of my control and it does not have a T generic argument.
Here is a cut-down example as a x-unit test of what I am doing and what I have tried.
Unfortunately, with INumber<TSelf> being so new there is not a lot of information about it online so before I give up, I figured I would see if anyone here knows how to achieve this.