【发布时间】:2019-04-11 12:43:36
【问题描述】:
我做了这样的代码。
private void MakeRowUsingMethodName(string pMethodName,params object[] var)
{
DataTable dt = dataSet1.Tables[0];
DataRow row = dt.NewRow();
row = dt.NewRow();
System.Reflection.MethodInfo pMethod = typeof(ShellSection).GetMethod(pMethodName);
int paramIndex = 0;
string paramType = string.Empty;
string paramName = string.Empty;
int paramCount = pMethod.GetParameters().Length;
string MethodName = pMethod.Name;
foreach (ParameterInfo pParameter in pMethod.GetParameters())
{
paramIndex = pParameter.Position;
paramName = pParameter.Name;
paramType = pParameter.ParameterType.Name;
row[paramIndex] = var[paramIndex];
}
dt.Rows.Add(row);
}
现在工作正常,但我希望使用其他类更灵活。
但这部分对我来说很难。
System.Reflection.MethodInfo pMethod = typeof(ShellSection).GetMethod(pMethodName);
“ShellSection”是 ClassName,
所以我想知道它可以将 ClassName 更改为字符串值。
而且我不知道这个方法转换成全局方法。
如果只有这部分可以修改,我可以制作更灵活的代码。
PS。
我会解决我的问题。
string className = "ShellSection";或者其他的东西
typeof("ShellSection").GetMethod(pMethodName);或
typeof(className).GetMethod(pMethodName);
我在问上面的可能性和操作方法。
【问题讨论】:
-
我先读了,但英文不太好,看不懂题。我简要地让你知道如何使用它,我立即应用它。感谢您的评论。