ExpressionToCode: Doesn't work with ValueTuples
Hey, I just found this lib and it is absolutely awesome!
The only issue I found so far is that it really doesn’t like Value Tuples.
First, it seems like the C# Team explicitly forbade using == in expressions, if you try PAssert.That(() => (5, "a", 1.1) == (5, "a", 1.1)); you get a compiler error
1>Tests.cs(75,32,75,62): error CS8382: An expression tree may not contain a tuple == or != operator 1>Tests.cs(75,32,75,45): error CS8143: An expression tree may not contain a tuple literal. 1>Tests.cs(75,49,75,62): error CS8143: An expression tree may not contain a tuple literal.
Second I thought I was smart and tried to use .Equals, which doesn’t work either.

Microsoft (R) Roslyn C# Compiler version 2.8.0.62830
Loading context from 'CSharpInteractive.rsp'.
Type "#help" for more information.
> #r "C:\Users\lr\.nuget\packages\expressiontocodelib\2.7.0\lib\net452\ExpressionToCodeLib.dll"
> var actual = (1, "2", 3.3);
> var expected = (2, "3", 4.4);
> using ExpressionToCodeLib;
.
. PAssert.That(() => actual.Equals(expected));
Cannot resolve method Boolean Equals(System.ValueTuple`3[System.Int32,System.__Canon,System.Double]) because the declaring type of the method handle System.ValueTuple`3[T1,T2,T3] is generic. Explicitly provide the declaring type to GetMethodFromHandle.
+ System.Reflection.MethodBase.GetMethodFromHandle(System.RuntimeMethodHandle)
>
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 15 (12 by maintainers)
Yep!
(And yeah, it’s a shame there are so many C# features that are disabled in expression trees…)
Related: https://github.com/dotnet/roslyn/issues/12897