c# - WPF SimpleCommand possible with generics? -
I am using this code to create a simple command:
public Class SimpleCommand: ICommand {Public Prophecy & amp; Object & gt; CanExecuteDelegate {get; Set; } Public Action & lt; Object & gt; ExecuteDelegate {get; Set; } #region ICommand Member Public Bull CanExecute {Object Parameter} {If CanExecuteDelegate! = Faucet} Return CanExecuteDelegate (parameter); Return true; // if there is no one can execute the default to correct} Public Event EventHandler CanExecuteChanged {addManager.RequerySuggested = value; } Remove {CommandManager.RequerySuggested - = Value; }} Execute Public Zero (Object Parameter) {If (ExecuteDelegate! = Null) ExecuteDelegate (Parameter); } #endregion}
I did not write this down. But I enjoy using it when I use it so it ends in this way:
// This is the value that the UI sets in command in the public SimpleCommand DoSomethingCommand {get; Set; } Public DoSomethingCommandConstructor () {DoSomethingCommand = New SimpleCommand {ExecuteDelegate = x = & gt; Run command (x)}; } Private Zero RunCommand (object o) {// to run the command}
The problem with this is that the parameter of RunCommand is an object I think is bad by generic I have always been told that I always want to know the IDE / compiler how I am working, it is casting out.
Can this normal commodity class be implemented using generics?
Surely you were told about the implementation of the prism, but the CodePlex source tab is not working . This will look something like this:
Public class SimpleCommand & lt; T & gt; : ICMMand {Public Liberation & lt; T & gt; CanExecuteDelegate {get; Set; } Public Action & lt; T & gt; ExecuteDelegate {get; Set; } #region ICommand Member Public Bull CanExecute {Object Parameters} {CanExecuteDelegate! =) Back CanExecuteDelegate (T) parameter); Return true; // if there is no one can execute the default to correct} Public Event EventHandler CanExecuteChanged {addManager.RequerySuggested = value; } Remove {CommandManager.RequerySuggested - = Value; }} Public Zero executed (object parameter) {if (ExecuteDelegate! = Null) ExecuteDelegate ((T) parameter); } #endrian}
Incidentally, using simple commodity in your question is a little bit of Twitter. Instead:
DoSomethingCommand = New Simple Command {ExecuteDelegate = x = & gt; Run command (x)};
You may just:
dosomingcommand = new simple command {ExecuteDelegate = this.RunCommand};
Specifying the lambda is really useful if you are inline working like this:
DoSomethingCommand = new SimpleCommand {ExecuteDelegate = o = Gt; this. Selected item = o, cancaculate delegate = o = & gt; Oh! = Null};
Comments
Post a Comment