我有以下情况:
public class Restriction
{
public string RestrictionName { get; set; }
public bool Eval(decimal Value2)
{
Type typeRestriction = Type.GetType(RestrictionName);
return (bool)typeRestriction.InvokeMember("Eval",
BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static,
null,
null,
new object[] { this, Value2 });
}
/* Nested Classes */
class A
{
public static bool Eval(Restriccion r, decimal value)
{
// Do something
}
}
class B
{
public static bool Eval(Restriccion r, decimal value)
{
// Do something
}
}
}
当我尝试时:
Restriction r = new Restriction();
r.RestrictionName = "A";
r.Value = 15;
r.Eval(16);
我得到System.NullReferenceException: Object reference not set to an instance of an object.
调试显示我 typeRestriction
是空的。为什么?嵌套类有特殊处理吗?