[corlib] Avoid unnecessary ephemeron array resizes
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Base / Core / Internal / PropertyEditing / FromExpression / Framework / Data / DelegateCommand.cs
1 // -------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All Rights Reserved.
3 // -------------------------------------------------------------------
4 //From \\authoring\Sparkle\Source\1.0.1083.0\Common\Source\Framework\Data
5 namespace System.Activities.Presentation.Internal.PropertyEditing.FromExpression.Framework.Data
6 {
7     using System;
8     using System.Windows.Input;
9     using System.Diagnostics.CodeAnalysis;
10     using System.Runtime;
11
12     internal sealed class DelegateCommand : ICommand
13     {
14         private SimpleEventHandler handler;
15         private bool isEnabled = true;
16
17         public DelegateCommand(SimpleEventHandler handler)
18         {
19             this.handler = handler;
20         }
21
22
23         public event EventHandler CanExecuteChanged;
24
25         public bool IsEnabled
26         {
27             get { return this.isEnabled; }
28         }
29         void ICommand.Execute(object arg)
30         {
31             this.handler();
32         }
33
34         bool ICommand.CanExecute(object arg)
35         {
36             return this.IsEnabled;
37         }
38
39         [SuppressMessage(FxCop.Category.Performance, FxCop.Rule.AvoidUncalledPrivateCode, Justification = "This is required by the ICommand interface.")]
40         private void OnCanExecuteChanged()
41         {
42             if (this.CanExecuteChanged != null)
43             {
44                 this.CanExecuteChanged(this, EventArgs.Empty);
45             }
46         }
47         public delegate void SimpleEventHandler();
48     }
49 }