当使用包含引用类型的参数调用 getMethod 时,MethodInfo 显示 null
MethodInfo showing null when getMethod is invoked with parameters containing reference type
public abstract class DbAttribute : IComparable
{
}
public abstract bool GetString(DbAttribute attributeName, ref string attributeValue);
Assembly testAssembly = null;
Type attributeA = testAssembly.GetType("A.Core.Data.DbAttribute");
Type elementA = testAssembly.GetType("A.Core.Data.DbElement");
MethodInfo mi = elementA.GetMethod("GetString", new Type[] { attributeA, typeof(System.String)});
mi
是空事件,尽管 elementA.getMethods()
告诉我 GetString
方法。我想我在参数 attributeA
.
上做错了什么
如果我使用 typeof(System.Object)
而不是 attributeA,它仍然是 returns null。
请建议如何在这种情况下正确使用 GetMethod
。
我认为是ref参数引起的
MethodInfo mi =ElementA.GetMethod("GetString",new Type[] { typeof(AttributeA) ,typeof(System.String).MakeByRefType()});
public abstract class DbAttribute : IComparable
{
}
public abstract bool GetString(DbAttribute attributeName, ref string attributeValue);
Assembly testAssembly = null;
Type attributeA = testAssembly.GetType("A.Core.Data.DbAttribute");
Type elementA = testAssembly.GetType("A.Core.Data.DbElement");
MethodInfo mi = elementA.GetMethod("GetString", new Type[] { attributeA, typeof(System.String)});
mi
是空事件,尽管 elementA.getMethods()
告诉我 GetString
方法。我想我在参数 attributeA
.
如果我使用 typeof(System.Object)
而不是 attributeA,它仍然是 returns null。
请建议如何在这种情况下正确使用 GetMethod
。
我认为是ref参数引起的
MethodInfo mi =ElementA.GetMethod("GetString",new Type[] { typeof(AttributeA) ,typeof(System.String).MakeByRefType()});