Dynamic property assignment passing interface property
I have a generic class with ICommand
properties. This is a composite object that use as child object that have is hown ICommand
properties.
I was searching a system to define during runtime the interface to use with this class and the command properties of child object that have to be "used" like the ICommand
property of generic.
Finally having something like this:
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;
Actually with Action<T,ICommand>
i define a delegate that return the "cor开发者_开发问答rect" ICommand
of child class.
What could be the better way to achieve this in your opinions?
Don't you really just want an ICommand that has an Action as a property rather than making some kind of factory.
mvvmlight toolkit has such a command.
RelayCommand
RelayCommandGeneric
精彩评论