mardi 22 novembre 2016

Call generic method with Expression through reflection

I Have generic method , wich should return last record from table:

    public T FindLast<TKey>(Expression<Func<T,TKey>> specification = null)
    {
        return specification == null
            ? Set().LastOrDefault()
            : Set().OrderBy(specification).LastOrDefault();
    }

I need to call it through reflection

var methodCreateReadRepositoryAttr = (entityMetadata.GetEntityAttributeType() != null) ? 
typeof(IRepositoryFactory).GetMethod("CreateReadRepository").MakeGenericMethod(entityMetadata.GetEntityAttributeType()) : null;

var methodEntityGet3 = attributeReadRepository.GetType().GetMethod("FindLast", new Type[] { typeof(Expression<Func<ArticleAttribute,int>>) });

But in debug methodEntityGet3 equal null. What did i wrong?





Aucun commentaire:

Enregistrer un commentaire