I need to based on string type - for example 'UserModel' execute method
Task<IEnumerable<T>> QueryAsync<T>(string sqlStatment, DynamicParameters parameters, CommandType commandType = CommandType.StoredProcedure, int timeout = 90, string connectionId = "Default");
so I have
string TypeName = "UserModel";
Type type = Type.GetType("XXX.Shared.CoreClasses."+ TypeName+", XX.Shared")!;
if(type is null) throw new ArgumentException(string.Format("type {0} not found", TypeName));
IList l = (IList)Activator
.CreateInstance(typeof(List<>)
.MakeGenericType(type))!;
System.Reflection.MethodInfo method = _sql.GetType().GetMethods().Where(c => c.Name == ("QueryAsync")
&& c.GetParameters()[1].ParameterType == typeof(DynamicParameters)).First().MakeGenericMethod(new Type[] { type });
object[] args = { SPname,d, CommandType.StoredProcedure,timeout };//not relevant
so now how to fill this l list with this method ?
like
l= await method.Invoke(this, args)!;
- it yeals at me about casting / object canot be awaited ? how to do this properly ? is something like this slow ? or nowdays it does not matter until it will have to execute like xxxx times/sec ? thanks and regards !