我有以下情形:嵌套类和动态调用问题
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
为空。为什么?嵌套类有特殊待遇吗?
这是[记录在这里](http://msdn.microsoft.com/en-us/library/w3f99sx1.aspx)。 – 2013-03-15 15:21:41