C# Reflection – Passing Type Variable to a Generic Function with Return Value
public class DAO { public IQueryable<T> PrepareQuery<T>(SoccerDAO.SoccerEntities context, string where = null) where T : class { IQueryable<T> query = context.Set<T>(); if (where != null) query = query.Where(where); return query; } } |
public JArray Post (JObject parameter) { using ( … … ) { … … DAO dao = new DAO(); MethodInfo method = dao.GetType().GetMethod("PrepareQuery").MakeGenericMethod(new Type[] { typeof(SoccerDAO.TEAM) }); return JArray.FromObject( method.Invoke(lib, new object[] { context, "TEAM_ID = 1" })); } } |