Skip to content

Commit

Permalink
Merge branch 'release/0.29.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
hazzik committed Feb 4, 2021
2 parents 9914b70 + aeff877 commit 66746d4
Show file tree
Hide file tree
Showing 22 changed files with 249 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Detail of supported commands
============
## Documentation produced for DelegateDecompiler, version 0.28.0 on Friday, 23 October 2020 15:02
## Documentation produced for DelegateDecompiler, version 0.29.0 on Thursday, 04 February 2021 16:03

This file documents what linq commands **DelegateDecompiler** supports when
working with [Entity Framework v6.1](http://msdn.microsoft.com/en-us/data/aa937723) (EF).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Detail With Sql of supported commands
============
## Documentation produced for DelegateDecompiler, version 0.28.0 on Friday, 23 October 2020 15:02
## Documentation produced for DelegateDecompiler, version 0.29.0 on Thursday, 04 February 2021 16:03

This file documents what linq commands **DelegateDecompiler** supports when
working with [Entity Framework v6.1](http://msdn.microsoft.com/en-us/data/aa937723) (EF).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Summary of supported commands
============
## Documentation produced for DelegateDecompiler, version 0.28.0 on Friday, 23 October 2020 15:02
## Documentation produced for DelegateDecompiler, version 0.29.0 on Thursday, 04 February 2021 16:03

This file documents what linq commands **DelegateDecompiler** supports when
working with [Entity Framework v6.1](http://msdn.microsoft.com/en-us/data/aa937723) (EF).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Detail of supported commands
============
## Documentation produced for DelegateDecompiler, version 0.28.0 on Friday, 23 October 2020 15:03
## Documentation produced for DelegateDecompiler, version 0.29.0 on Thursday, 04 February 2021 16:04

This file documents what linq commands **DelegateDecompiler** supports when
working with [Entity Framework Core](https://docs.microsoft.com/en-us/ef/core/) (EF).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Detail With Sql of supported commands
============
## Documentation produced for DelegateDecompiler, version 0.28.0 on Friday, 23 October 2020 15:03
## Documentation produced for DelegateDecompiler, version 0.29.0 on Thursday, 04 February 2021 16:04

This file documents what linq commands **DelegateDecompiler** supports when
working with [Entity Framework Core](https://docs.microsoft.com/en-us/ef/core/) (EF).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Summary of supported commands
============
## Documentation produced for DelegateDecompiler, version 0.28.0 on Friday, 23 October 2020 15:03
## Documentation produced for DelegateDecompiler, version 0.29.0 on Thursday, 04 February 2021 16:04

This file documents what linq commands **DelegateDecompiler** supports when
working with [Entity Framework Core](https://docs.microsoft.com/en-us/ef/core/) (EF).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Detail of supported commands
============
## Documentation produced for DelegateDecompiler, version 0.28.0 on Friday, 23 October 2020 15:03
## Documentation produced for DelegateDecompiler, version 0.29.0 on Thursday, 04 February 2021 16:05

This file documents what linq commands **DelegateDecompiler** supports when
working with [Entity Framework Core](https://docs.microsoft.com/en-us/ef/core/) (EF).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Detail With Sql of supported commands
============
## Documentation produced for DelegateDecompiler, version 0.28.0 on Friday, 23 October 2020 15:03
## Documentation produced for DelegateDecompiler, version 0.29.0 on Thursday, 04 February 2021 16:05

This file documents what linq commands **DelegateDecompiler** supports when
working with [Entity Framework Core](https://docs.microsoft.com/en-us/ef/core/) (EF).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Summary of supported commands
============
## Documentation produced for DelegateDecompiler, version 0.28.0 on Friday, 23 October 2020 15:03
## Documentation produced for DelegateDecompiler, version 0.29.0 on Thursday, 04 February 2021 16:05

This file documents what linq commands **DelegateDecompiler** supports when
working with [Entity Framework Core](https://docs.microsoft.com/en-us/ef/core/) (EF).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Detail of supported commands
============
## Documentation produced for DelegateDecompiler, version 0.28.0 on Friday, 23 October 2020 15:03
## Documentation produced for DelegateDecompiler, version 0.29.0 on Thursday, 04 February 2021 16:05

This file documents what linq commands **DelegateDecompiler** supports when
working with [Entity Framework Core](https://docs.microsoft.com/en-us/ef/core/) (EF).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Detail With Sql of supported commands
============
## Documentation produced for DelegateDecompiler, version 0.28.0 on Friday, 23 October 2020 15:03
## Documentation produced for DelegateDecompiler, version 0.29.0 on Thursday, 04 February 2021 16:05

This file documents what linq commands **DelegateDecompiler** supports when
working with [Entity Framework Core](https://docs.microsoft.com/en-us/ef/core/) (EF).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Summary of supported commands
============
## Documentation produced for DelegateDecompiler, version 0.28.0 on Friday, 23 October 2020 15:03
## Documentation produced for DelegateDecompiler, version 0.29.0 on Thursday, 04 February 2021 16:05

This file documents what linq commands **DelegateDecompiler** supports when
working with [Entity Framework Core](https://docs.microsoft.com/en-us/ef/core/) (EF).
Expand Down
9 changes: 9 additions & 0 deletions src/DelegateDecompiler.Tests/EnumTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,15 @@ public void Issue98B()
Test(expected, compiled);
}

[Test, Ignore("Not fixed yet")]
public void Issue160()
{
Expression<Func<int?, bool>> expected1 = x => (TestEnum?) x == TestEnum.Bar;
Expression<Func<int?, bool>> expected2 = x => (int?) x == (int?) TestEnum.Bar;
Func<int?, bool> compiled = x => (TestEnum?) x == TestEnum.Bar;
Test(expected1, expected2, compiled);
}

private static bool TestEnumMethod(TestEnum p0)
{
throw new NotImplementedException();
Expand Down
58 changes: 58 additions & 0 deletions src/DelegateDecompiler.Tests/Issue166.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;

namespace DelegateDecompiler.Tests
{
[TestFixture]
public class Issue166 : DecompilerTestsBase
{
[Test]
public void ShouldSupportInstanceClosures()
{
var comments = new Comment[0];
var expected = comments.AsQueryable().Select(c => new CommentDto
{
HasUserPurchasedTheCourse = c.User.Purchases.Any(p => p.Items.Any(i => i.CourseId == c.CourseId)),
});
var actual = comments.AsQueryable().Select(c => ToCommentDto(c)).Decompile();
AssertAreEqual(expected.Expression, actual.Expression);
}

[Decompile]
static CommentDto ToCommentDto(Comment comment)
{
return new CommentDto
{
HasUserPurchasedTheCourse = comment.User.Purchases.Any(p => p.Items.Any(i => i.CourseId == comment.CourseId)),
};
}

class Comment
{
public User User { get; set; }

public int CourseId { get; set; }
}

class User
{
public IEnumerable<Purchase> Purchases { get; set; }
}

class PurchaseItem
{
public int CourseId { get; set; }
}

class Purchase
{
public IEnumerable<PurchaseItem> Items { get; set; }
}

class CommentDto
{
public bool HasUserPurchasedTheCourse { get; set; }
}
}
}
49 changes: 49 additions & 0 deletions src/DelegateDecompiler.Tests/Issue167.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;

namespace DelegateDecompiler.Tests
{
[TestFixture]
public class Issue167 : DecompilerTestsBase
{
[Test]
public void ShouldFlattenTransparentExpressions()
{
var comments = new Comment[0];
var expected = comments.AsQueryable().Select(c => new CommentDto
{
IsUserPurchaser = c.Purchases.Any(p => p.UserId == c.UserId)
});
var actual = comments.AsQueryable().Select(c => ToCommentDto(c)).Decompile();

AssertAreEqual(expected.Expression, actual.Expression);
}

[Decompile]
static CommentDto ToCommentDto(Comment comment)
{
return new CommentDto
{
IsUserPurchaser = comment.Purchases.Any(p => p.UserId == comment.UserId),
};
}

public class Comment
{
public int UserId { get; set; }

public IEnumerable<Purchase> Purchases { get; }
}

public class Purchase
{
public int UserId { get; set; }
}

public class CommentDto
{
public object IsUserPurchaser { get; set; }
}
}
}
44 changes: 44 additions & 0 deletions src/DelegateDecompiler.Tests/Issue171.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using NUnit.Framework;

namespace DelegateDecompiler.Tests
{
[TestFixture]
public class Issue171
{
[Test]
public void ShouldSupportStructsWithoutInitializer()
{
var method = typeof(Issue171).GetMethod(nameof(X1));
var expression = method.Decompile();

Assert.That(expression.ToString(), Is.EqualTo("this => new DataOnStack() {StatementCount = 1}"));
}

[Test]
public void ShouldSupportStructsWithInitializer()
{
var method = typeof(Issue171).GetMethod(nameof(X2));
var expression = method.Decompile();

Assert.That(expression.ToString(), Is.EqualTo("this => new DataOnStack() {StatementCount = 1}"));
}

public DataOnStack X1()
{
DataOnStack x;
x.StatementCount = 1;
return x;
}


public DataOnStack X2()
{
return new DataOnStack {StatementCount = 1};
}

public struct DataOnStack
{
public uint StatementCount;
}
}
}
4 changes: 3 additions & 1 deletion src/DelegateDecompiler/DecompileExpressionVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ Expression Decompile(MethodInfo method, Expression instance, IList<Expression> a
}
}

return Visit(new ReplaceExpressionVisitor(expressions).Visit(expression.Body));
var body = new ReplaceExpressionVisitor(expressions).Visit(expression.Body);
body = TransparentIdentifierRemovingExpressionVisitor.RemoveTransparentIdentifiers(body);
return Visit(body);
}
}
}
21 changes: 21 additions & 0 deletions src/DelegateDecompiler/MemberExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Reflection;

namespace DelegateDecompiler
{
internal static class MemberExtensions
{
public static Type FieldOrPropertyType(this MemberInfo member)
{
switch (member)
{
case FieldInfo field:
return field.FieldType;
case PropertyInfo property:
return property.PropertyType;
default:
throw new NotSupportedException($"MemberInfo {member} is not supported");
}
}
}
}
Loading

0 comments on commit 66746d4

Please sign in to comment.