axelheer / nein-linq

NeinLinq provides helpful extensions for using LINQ providers such as Entity Framework that support only a minor subset of .NET functions, reusing functions, rewriting queries, even making them null-safe, and building dynamic queries using translatable predicates and selectors.
MIT License
521 stars 22 forks source link

InjectLambda works with private method in base class #30

Closed rostunic closed 2 years ago

rostunic commented 2 years ago

It was not possible to have a base class with a public method, that calls a private annotated method:

public abstract class Base
{
   public IQueryable<Person> PublicMethod(IQueryable<Person> list) => list.Select(p => PrivateMethod(p));

   [InjectLambda]
   private string PrivateMethod(Person person) => throw new NotSupportedException($"Unable to process {value.Name}.");

   protected abstract Expression<Func<Person, string>> PrivateMethod();
}
public class Sub : Base
{
   public override Expression<Func<Person, string>> PrivateMethod() => v => Math.Round(v.Distance / v.Time, digits);
}

The reason was that the reflection method target.GetMethods(Everything) is not able to find private methods of the base types of target. So I added a recursion which searchs in the base type if no result was found on the subtype.

axelheer commented 2 years ago

Nice 🤗

codecov[bot] commented 2 years ago

Codecov Report

Merging #30 (b642a80) into main (de6feee) will increase coverage by 0.00%. The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #30   +/-   ##
=======================================
  Coverage   95.20%   95.21%           
=======================================
  Files          51       51           
  Lines        1064     1066    +2     
  Branches      231      232    +1     
=======================================
+ Hits         1013     1015    +2     
  Misses         29       29           
  Partials       22       22           
Impacted Files Coverage Δ
src/NeinLinq/InjectLambdaSignature.cs 92.30% <100.00%> (+0.24%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update de6feee...b642a80. Read the comment docs.

axelheer commented 2 years ago

Thanks! ❤️