从两个类似的方法获取MethodInfo

时间:2016-07-11 14:45:35

标签: c#

在Entity Framework Core中,使用C#6,有以下3种方法:

public static class EntityFrameworkQueryableExtensions {

  public static IIncludableQueryable<TEntity, TProperty> Include<TEntity, TProperty>([NotNullAttribute] this IQueryable<TEntity> source, [NotNullAttribute] Expression<Func<TEntity, TProperty>> navigationPropertyPath) where TEntity : class;

  public static IIncludableQueryable<TEntity, TProperty> ThenInclude<TEntity, TPreviousProperty, TProperty>([NotNullAttribute] this IIncludableQueryable<TEntity, ICollection<TPreviousProperty>> source, [NotNullAttribute] Expression<Func<TPreviousProperty, TProperty>> navigationPropertyPath) where TEntity : class;

  public static IIncludableQueryable<TEntity, TProperty> ThenInclude<TEntity, TPreviousProperty, TProperty>([NotNullAttribute] this IIncludableQueryable<TEntity, TPreviousProperty> source, [NotNullAttribute] Expression<Func<TPreviousProperty, TProperty>> navigationPropertyPath) where TEntity : class;

}

我需要使用泛型调用这些方法。对于Include我正在做这样的事情:

MethodInfo _include = 
  typeof(EntityFrameworkQueryableExtensions)
          .GetTypeInfo()
          .GetDeclaredMethods(nameof(EntityFrameworkQueryableExtensions.Include))
          .Single(x => x.GetParameters().Select(y => y.ParameterType.GetGenericTypeDefinition())
          .SequenceEqual(new[] { typeof(IQueryable<>), typeof(Expression<>) }));

我的问题是如何区分2个ThenInclude方法。人们只有一个区别:

IIncludableQueryable<TEntity, ICollection<TPreviousProperty>>

另一个

IIncludableQueryable<TEntity, TPreviousProperty>
顺便说一句,如果有人知道简化我的代码的方法,请告诉我。

0 个答案:

没有答案
相关问题