我必须重写哪种方法DynamicObject
才能根据使用实例的上下文获得不同的行为(在动态类中)?
这是我要完成的一个示例:
class DynamicTest : DynamicObject
{
public DynamicTest(string xyz)
{
_xyz = xyz;
}
private string _xyz;
//TODO: what do I need to implement to get required behaviour?
}
class Program
{
static void Main(string[] args)
{
dynamic foo = new DynamicTest("test);
if (foo) // treat foo as boolean
{ // jump in here when _xyz of foo has a value
System.Console.WriteLine(foo); //treat foo as string
}
else
{ // jump in here when _xyz of foo is null
System.Console.WriteLine("No Value In Object");
}
}
}