这完全没有涉及你的情景,而是如何使用一种动态的客观执行,作为你们的物体的cor子? 这将使你能够接触原始物体和额外财产。 缺乏类似扩大目标,但首先依靠自己的实例数据。
与此类似:
public class Expando : DynamicObject
{
public dynamic Instance;
Dictionary<string, dynamic> ExtraProperties = new Dictionary<string, dynamic>();
public Expando(object instance)
{
Instance = instance;
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
try
{
result = ReflectionUtils.GetProperty(Instance, binder.Name);
return true;
}
catch
{
if (ExtraProperties.Keys.Contains(binder.Name))
{
result = ExtraProperties[binder.Name];
return true;
}
}
result = null;
return false;
}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
try
{
ReflectionUtils.SetProperty(Instance, binder.Name, value);
}
catch (Exception ex)
{
ExtraProperties[binder.Name] = value;
}
return true;
}
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
try
{
result = ReflectionUtils.CallMethod(Instance, binder.Name, args);
return true;
}
catch
{}
result = null;
return false;
}
}
但不幸的是,由于这里的反思使用(从。