繁体   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