-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for shimming operators #31
Comments
I can confirm that we do not currently support this. Given the following MVE: public class OverridenOperatorClass
{
public static explicit operator bool(OverridenOperatorClass c) => false;
}
public static void Main(string[] args)
{
Shim
.Replace(() => (bool) Is.A<OverridenOperatorClass>())
.With(delegate { return true; });
} This throws the following exception:
This seems to be caused by the expression type not being supported. Specifically, |
Please note, though, that the shim cannot be applied to a specific instance as the operator is static.
I've added support for shimming conversion operators. Please note, though, that the shim cannot be applied to a specific instance as the operator is static.
The modus operandi so far has been to:
I'm encountering some issues with the following operators:
Aside from the above operator shimming should be implemented now. Tests (both positive and negative) remain to be implemented for all operators. |
Please note, though, that the shim cannot be applied to a specific instance as the operator is static.
We now support: * Comparison * Equality * Most of arithmetic
We now support: * + * ++ * - * -- * ~ * true * false
How to handle double casting? That is, assume the following code: class OperatorsClass
{
public static implicit operator double(OperatorsClass c) => double.MinValue;
}
var instance = new OperatorsClass();
var doubleCasted = (long)(int)instance; // Double-cast Attempting to get the method from the expression |
Operators shimming is now implemented and the README has been updated. I did discover that when attempting to shim an operator for which the type has no overload (e.g. UPDATE 2024-04-12: I have added a better error message for the above scenario. |
Please note, though, that the shim cannot be applied to a specific instance as the operator is static.
We now support: * Comparison * Equality * Most of arithmetic
We now support: * + * ++ * - * -- * ~ * true * false
#31: Add support for shimming operators
Implicit vs. explicit operators.Confirm by trying it out in the sandbox.Currently not supported. Will be added in this issue and linked PR #33
Tasks
Tests
For all of the following operators we need:
The list of operators (and their names) is taken from here: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/operator-overloading#overloadable-operators
Operators to support
Arithmetic
I cannot find a good way to express this operation in an expression tree.true
I cannot find a good way to express this operation in an expression tree.false
x >>> yExpression trees cannot contain this operator. This is a limitation on the part of the compiler.Equality
Comparison
The text was updated successfully, but these errors were encountered: