From 3d26bffc074c7c00b794c385b35ccaf42e516d3a Mon Sep 17 00:00:00 2001 From: syneffort Date: Mon, 10 Jul 2023 17:38:39 +0900 Subject: [PATCH] command pattern --- .../CommandPatternSample/App.config | 6 + PacticeSolution/CommandPatternSample/App.xaml | 9 ++ .../CommandPatternSample/App.xaml.cs | 17 +++ .../Command/RelayCommand.cs | 39 ++++++ .../CommandPatternSample.csproj | 100 +++++++++++++++ .../CommandPatternSample/MainWindow.xaml | 28 +++++ .../CommandPatternSample/MainWindow.xaml.cs | 28 +++++ .../CommandPatternSample/Model/Emp.cs | 18 +++ .../Properties/AssemblyInfo.cs | 55 ++++++++ .../Properties/Resources.Designer.cs | 71 +++++++++++ .../Properties/Resources.resx | 117 ++++++++++++++++++ .../Properties/Settings.Designer.cs | 30 +++++ .../Properties/Settings.settings | 7 ++ .../ViewModel/EmpViewModel.cs | 72 +++++++++++ PacticeSolution/PacticeSolution.sln | 6 + 15 files changed, 603 insertions(+) create mode 100644 PacticeSolution/CommandPatternSample/App.config create mode 100644 PacticeSolution/CommandPatternSample/App.xaml create mode 100644 PacticeSolution/CommandPatternSample/App.xaml.cs create mode 100644 PacticeSolution/CommandPatternSample/Command/RelayCommand.cs create mode 100644 PacticeSolution/CommandPatternSample/CommandPatternSample.csproj create mode 100644 PacticeSolution/CommandPatternSample/MainWindow.xaml create mode 100644 PacticeSolution/CommandPatternSample/MainWindow.xaml.cs create mode 100644 PacticeSolution/CommandPatternSample/Model/Emp.cs create mode 100644 PacticeSolution/CommandPatternSample/Properties/AssemblyInfo.cs create mode 100644 PacticeSolution/CommandPatternSample/Properties/Resources.Designer.cs create mode 100644 PacticeSolution/CommandPatternSample/Properties/Resources.resx create mode 100644 PacticeSolution/CommandPatternSample/Properties/Settings.Designer.cs create mode 100644 PacticeSolution/CommandPatternSample/Properties/Settings.settings create mode 100644 PacticeSolution/CommandPatternSample/ViewModel/EmpViewModel.cs diff --git a/PacticeSolution/CommandPatternSample/App.config b/PacticeSolution/CommandPatternSample/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/PacticeSolution/CommandPatternSample/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/PacticeSolution/CommandPatternSample/App.xaml b/PacticeSolution/CommandPatternSample/App.xaml new file mode 100644 index 0000000..dcf1550 --- /dev/null +++ b/PacticeSolution/CommandPatternSample/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/PacticeSolution/CommandPatternSample/App.xaml.cs b/PacticeSolution/CommandPatternSample/App.xaml.cs new file mode 100644 index 0000000..7fda16c --- /dev/null +++ b/PacticeSolution/CommandPatternSample/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace CommandPatternSample +{ + /// + /// App.xaml에 대한 상호 작용 논리 + /// + public partial class App : Application + { + } +} diff --git a/PacticeSolution/CommandPatternSample/Command/RelayCommand.cs b/PacticeSolution/CommandPatternSample/Command/RelayCommand.cs new file mode 100644 index 0000000..2773bca --- /dev/null +++ b/PacticeSolution/CommandPatternSample/Command/RelayCommand.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Input; + +namespace CommandPatternSample.Command +{ + internal class RelayCommand : ICommand + { + private Func _canExecute; + private Action _executeAction; + + public event EventHandler CanExecuteChanged; + + public RelayCommand(Action executeAction, Func canExeute) + { + _executeAction = executeAction ?? throw new ArgumentNullException("Execute action is not null"); + _canExecute = canExeute; + } + + public RelayCommand(Action executeAction) : this(executeAction, null) + { + + } + + public bool CanExecute(object parameter) + { + bool result = _canExecute == null ? true : _canExecute.Invoke(parameter); + return result; + } + + public void Execute(object parameter) + { + _executeAction.Invoke(parameter); + } + } +} diff --git a/PacticeSolution/CommandPatternSample/CommandPatternSample.csproj b/PacticeSolution/CommandPatternSample/CommandPatternSample.csproj new file mode 100644 index 0000000..5cbfc1c --- /dev/null +++ b/PacticeSolution/CommandPatternSample/CommandPatternSample.csproj @@ -0,0 +1,100 @@ + + + + + Debug + AnyCPU + {D7C77FA4-195E-4247-90B2-C89BF5016FDE} + WinExe + CommandPatternSample + CommandPatternSample + v4.5 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + MainWindow.xaml + Code + + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + \ No newline at end of file diff --git a/PacticeSolution/CommandPatternSample/MainWindow.xaml b/PacticeSolution/CommandPatternSample/MainWindow.xaml new file mode 100644 index 0000000..cc0693e --- /dev/null +++ b/PacticeSolution/CommandPatternSample/MainWindow.xaml @@ -0,0 +1,28 @@ + + + + + + + + +