gpt4 book ai didi

c# - GetMethod 返回 null

转载 作者:行者123 更新时间:2023-11-30 20:38:45 25 4
gpt4 key购买 nike

好的,所以我有这门课:

public class tUObject
{
public const string strSelect = "SELECT Id, cName, Major FROM tUObject WHERE Id = ";

//constructors and stuff...

public virtual void FillElem(ref List<tUObject> l, DataSet ds)
{
//...
}
}

MainWindow() 中,我想使用 GetMethod() 进入 FillElem():

static List<tUObject> obj = new List<tUObject>();
static DataSet objDataSet = new DataSet();
//...
string strClass = objDataSet.Tables[0].Rows[0]["Class"].ToString(); //"tUObject"
Type t = Type.GetType("UniDB_WPF." + strClass); //tUObject with the assembly name
Type tlist = obj.GetType(); //list<tUObject>
Type tset = objDataSet.GetType(); //DataSet

//Getting strSelect from tUObject
string strAccessSelect = t.GetField("strSelect").GetRawConstantValue().ToString() + ((int)item.Tag).ToString();
//...
//Getting FillElem from tUObject
MethodInfo mi = t.GetMethod("FillElem", BindingFlags.Public, null, new[] { tlist, tset }, null);

问题是,GetMethod() 返回 null,而 GetField() 工作正常。 tlisttset 不为空,分别返回“List'1”和“DataSet”。那为什么会这样呢?

最佳答案

试试这个:

//Getting FillElem from tUObject
MethodInfo mi = t.GetMethod("FillElem", BindingFlags.Public | BindingFlags.Instance, null, new[] { tlist.MakeByRefType(), tset }, null);

关于c# - GetMethod 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34847470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com