【发布时间】:2014-03-22 00:17:56
【问题描述】:
我正在尝试使用 mixins 创建代理类型。在以下示例中,TypePresenter 实现 ICustomTypeDescriptor。当我创建一个实例时,“GetProperties”会引发 NotImplementedException。
当我对 ProxyGenerator.CreateClassProxy 做同样的事情时,一切正常!我想获得类型,以便我可以将它与我的 IoC 一起使用。
var options = new ProxyGenerationOptions();
options.AddMixinInstance(new TypePresenter<SampleViewModel>());
var builder = new DefaultProxyBuilder();
var sampleType = builder.CreateClassProxyType(typeof(SampleViewModel), null, options);
var sample = Activator.CreateInstance(sampleType);
var typeDescriptor = (ICustomTypeDescriptor)sample;
// Error happens on this line.
var properties = typeDescriptor.GetProperties();
var property = properties["DoIt"];
Assert.IsNotNull(property);
Assert.IsTrue(property.PropertyType == typeof(ICommand));
为什么这不起作用?
【问题讨论】: