簡體   English   中英

動態屬性分配傳遞接口屬性

[英]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的委托。

在您看來,實現此目標的更好方法是什么?

您真的不只是想要一個將Action作為屬性的ICommand而不是制造某種工廠的方法。

mvvmlight工具箱具有這樣的命令。

中繼命令

中繼命令通用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM