Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions src/DelegateDecompiler.Tests/NestedExpressionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ public class NestedExpressionsTests : DecompilerTestsBase
int M1() => 0;
static int M2() => 0;

readonly IQueryable<int> fQref1 = Enumerable.Empty<int>().AsQueryable();
static IQueryable<int> fQref2 = Enumerable.Empty<int>().AsQueryable();
[Decompile]
IQueryable<int> pQref1 => Enumerable.Empty<int>().AsQueryable();
[Decompile]
static IQueryable<int> pQref2 => Enumerable.Empty<int>().AsQueryable();
[Decompile]
IQueryable<int> MQref1() => Enumerable.Empty<int>().AsQueryable();
[Decompile]
static IQueryable<int> MQref2() => Enumerable.Empty<int>().AsQueryable();
[Decompile]
IQueryable<int> ParamedMQref1(int floor) => Enumerable.Empty<int>().AsQueryable().Where(x => x >= floor);
[Decompile]
static IQueryable<int> ParamedMQref2(int floor) => Enumerable.Empty<int>().AsQueryable().Where(x => x >= floor);

[Test]
public void TestNestedExpression()
{
Expand Down Expand Up @@ -178,5 +193,107 @@ public void TestFuncWithStaticMethodClosure()
ints => ints.SingleOrDefault(i => i == M2())
);
}

[Test]
public void TestQueryableBoundAsVariable()
{
IQueryable<int> query = Enumerable.Empty<int>().AsQueryable().Where(i => i >= 0);
Test<Func<IQueryable<int>, IQueryable<int>>>(
ints => query,
ints => query
);
}

[Test]
public void TestQueryableRefFromField()
{
Test<Func<IQueryable<int>, IQueryable<int>>>(
ints => fQref1.Where(i => i >= 0),
ints => fQref1.Where(i => i >= 0)
);
}

[Test]
public void TestQueryableRefFromStaticField()
{
Test<Func<IQueryable<int>, IQueryable<int>>>(
ints => fQref2.Where(i => i >= 0),
ints => fQref2.Where(i => i >= 0)
);
}

[Test]
public void TestQueryableRefFromProperty()
{
Test<Func<IQueryable<int>, IQueryable<int>>>(
ints => Enumerable.Empty<int>().AsQueryable().Where(i => i >= 0),
ints => pQref1.Where(i => i >= 0)
);
}

[Test]
public void TestQueryableRefFromStaticProperty()
{
Test<Func<IQueryable<int>, IQueryable<int>>>(
ints => Enumerable.Empty<int>().AsQueryable().Where(i => i >= 0),
ints => pQref2.Where(i => i >= 0)
);
}

[Test]
public void TestQueryableRefFromMethod()
{
Test<Func<IQueryable<int>, IQueryable<int>>>(
ints => Enumerable.Empty<int>().AsQueryable().Where(i => i >= 0),
ints => MQref1().Where(i => i >= 0)
);
}

[Test]
public void TestQueryableRefFromStaticMethod()
{
Test<Func<IQueryable<int>, IQueryable<int>>>(
ints => Enumerable.Empty<int>().AsQueryable().Where(i => i >= 0),
ints => MQref2().Where(i => i >= 0)
);
}

[Test]
public void TestQueryableRefFromMethodWithBoundParameters()
{
var floor = 10;
Test<Func<IQueryable<int>, IQueryable<int>>>(
ints => Enumerable.Empty<int>().AsQueryable().Where(x => x >= floor).Where(i => i >= 0),
ints => ParamedMQref1(floor).Where(i => i >= 0)
);
}

[Test]
public void TestQueryableRefFromStaticMethoWithBoundParameters()
{
var floor = 10;
Test<Func<IQueryable<int>, IQueryable<int>>>(
ints => Enumerable.Empty<int>().AsQueryable().Where(x => x >= floor).Where(i => i >= 0),
ints => ParamedMQref1(floor).Where(i => i >= 0)
);
}

[Test]
public void TestQueryableRefFromMethodWithUnboundParameters()
{
Test<Func<IQueryable<int>, int, IQueryable<int>>>(
(ints, floor) => Enumerable.Empty<int>().AsQueryable().Where(x => x >= floor).Where(i => i >= 0),
(ints, floor) => ParamedMQref1(floor).Where(i => i >= 0)
);
}

[Test]
public void TestQueryableRefFromStaticMethoWithUnboundParameters()
{
Test<Func<IQueryable<int>, int, IQueryable<int>>>(
(ints, floor) => Enumerable.Empty<int>().AsQueryable().Where(x => x >= floor).Where(i => i >= 0),
(ints, floor) => ParamedMQref1(floor).Where(i => i >= 0)
);
}
}
}
4 changes: 3 additions & 1 deletion src/DelegateDecompiler/DecompileExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public static LambdaExpression Decompile(this MethodInfo method)

public static LambdaExpression Decompile(this MethodInfo method, Type declaringType)
{
return Cache.GetOrAdd(Tuple.Create(declaringType, method), DecompileDelegate).Value;
return (LambdaExpression)Cache
.GetOrAdd(Tuple.Create(declaringType, method), DecompileDelegate)
.Value.Decompile();
}

public static IQueryable<T> Decompile<T>(this IQueryable<T> self)
Expand Down