我的课堂上有这个方法TeacherBusiness.cs:
public List<Teacher> GetList(List<long> ids)
Run Code Online (Sandbox Code Playgroud)
我想通过反射来调用它。这就是我所做的:
var ids = new List<long> { 1, 2, 3 }
var business = typeof(TeacherBusiness);
var getListMethod = business.GetMethod("GetList", new System.Type[] { typeof(List<long>) });
var entities = getListMethod.Invoke(business, new object[] { ids });
Run Code Online (Sandbox Code Playgroud)
但是,当我调用它时,我收到此错误:
对象与目标类型不匹配。
我被困在这一点上。
如果我将调用代码更改为getListMethod.Invoke(business, ids)代码将无法编译,并且出现此错误:
错误CS1503:参数2:无法从“System.Collections.Generic.List”转换为“对象?[]?”
我应该怎么办?