2 using System.Reflection;
3 using System.Windows.Input;
4 using System.ComponentModel;
6 namespace Tizen.NUI.Binding
8 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
9 [EditorBrowsable(EditorBrowsableState.Never)]
10 public sealed class Command<T> : Command
12 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
13 [EditorBrowsable(EditorBrowsableState.Never)]
14 public Command(Action<T> execute)
17 if (IsValidParameter(o))
25 throw new ArgumentNullException(nameof(execute));
29 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
30 [EditorBrowsable(EditorBrowsableState.Never)]
31 public Command(Action<T> execute, Func<T, bool> canExecute)
34 if (IsValidParameter(o))
38 }, o => IsValidParameter(o) && canExecute((T)o))
41 throw new ArgumentNullException(nameof(execute));
42 if (canExecute == null)
43 throw new ArgumentNullException(nameof(canExecute));
46 static bool IsValidParameter(object o)
50 // The parameter isn't null, so we don't have to worry whether null is a valid option
56 // The parameter is null. Is T Nullable?
57 if (Nullable.GetUnderlyingType(t) != null)
62 // Not a Nullable, if it's a value type then null is not valid
63 return !t.GetTypeInfo().IsValueType;
68 /// Defines an ICommand implementation that wraps a Action.
70 [EditorBrowsable(EditorBrowsableState.Never)]
71 public class Command : ICommand
73 readonly Func<object, bool> _canExecute;
74 readonly Action<object> _execute;
77 /// Initializes a new instance of the Command class.
79 /// <param name="execute">An instance to execute when the Command is executed.</param>
80 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
81 [EditorBrowsable(EditorBrowsableState.Never)]
82 public Command(Action<object> execute)
85 throw new ArgumentNullException(nameof(execute));
91 /// Initializes a new instance of the Command class.
93 /// <param name="execute">An Action to execute when the Command is executed.</param>
94 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
95 [EditorBrowsable(EditorBrowsableState.Never)]
96 public Command(Action execute) : this(o => execute())
99 throw new ArgumentNullException(nameof(execute));
103 /// Initializes a new instance of the Command class.
105 /// <param name="execute">An Action to execute when the Command is executed.</param>
106 /// <param name="canExecute">A instance indicating if the Command can be executed.</param>
107 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
108 [EditorBrowsable(EditorBrowsableState.Never)]
109 public Command(Action<object> execute, Func<object, bool> canExecute) : this(execute)
111 if (canExecute == null)
112 throw new ArgumentNullException(nameof(canExecute));
114 _canExecute = canExecute;
118 /// Initializes a new instance of the Command class.
120 /// <param name="execute">An Action to execute when the Command is executed.</param>
121 /// <param name="canExecute">A instance indicating if the Command can be executed.</param>
122 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
123 [EditorBrowsable(EditorBrowsableState.Never)]
124 public Command(Action execute, Func<bool> canExecute) : this(o => execute(), o => canExecute())
127 throw new ArgumentNullException(nameof(execute));
128 if (canExecute == null)
129 throw new ArgumentNullException(nameof(canExecute));
133 /// Returns a Boolean indicating if the Command can be exectued with the given parameter.
135 /// <param name="parameter">An Object used as parameter to determine if the Command can be executed.</param>
136 /// <returns>true if the Command can be executed, false otherwise.</returns>
137 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
138 [EditorBrowsable(EditorBrowsableState.Never)]
139 public bool CanExecute(object parameter)
141 if (_canExecute != null)
142 return _canExecute(parameter);
148 /// Occurs when the target of the Command should reevaluate whether or not the Command can be executed.
150 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
151 [EditorBrowsable(EditorBrowsableState.Never)]
152 public event EventHandler CanExecuteChanged;
155 /// Invokes the execute Action.
157 /// <param name="parameter">An Object used as parameter for the execute Action.</param>
158 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
159 [EditorBrowsable(EditorBrowsableState.Never)]
160 public void Execute(object parameter)
166 /// Send a CanExecuteChanged.
168 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
169 [EditorBrowsable(EditorBrowsableState.Never)]
170 public void ChangeCanExecute()
172 EventHandler changed = CanExecuteChanged;
173 changed?.Invoke(this, EventArgs.Empty);