[英]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.