[英]Dynamic property assignment passing interface property
我有一个具有ICommand
属性的通用类。 这是一个复合对象,用作具有ICommand
属性的子对象。
我正在搜索一个系统,以在运行时期间定义用于此类的接口以及必须“使用”子对象的命令属性,例如通用的ICommand
属性。
终于有了这样的事情:
public TestDynamic<T>
{
public ICommand ChildCommand;
public T CompositeChild;
...
}
public interface ITestOne{
ICommand DoSomethin{get;set;}
}
public interface ITestTwo{
ICommand DoSomethingMore{get;set;}
}
ITestOne MyObj1=...
ITestTwo MyObj2=...
TestDynamic<ITestOne> TD1=...
TD1.DynamicRegistration((i)=>i.DoSomething);
TD1.ChildCommand.Execute();//DoSomething execution
TestDynamic<ITestTwo> TD2=...
TD2.CompositeChild=MyObj2;
TD2.DynamicRegistration((i)=>i.DoSomethingMore);
TD2.ChildCommand.Execute();//DoSomethingMore execution
//Those are done in a different moment. Where i can't simply set the property
TD1.CompositeChild=MyObj1;
TD1.CompositeChild=MyObj1;
实际上,使用Action<T,ICommand>
我定义了一个返回子类的“正确” ICommand
的委托。
在您看来,实现此目标的更好方法是什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.