[reflection] Coop handles icalls in System.Reflection and System.RuntimeTypeHandle...
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Model / DictionaryEditChange.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4
5 namespace System.Activities.Presentation.Model
6 {
7     using System;
8     using System.Collections.Generic;
9     using System.Text;
10     using System.Activities.Presentation.Services;
11
12     class DictionaryEditChange : ModelChange
13     {
14         public ModelItemDictionary Dictionary { get; set; }
15
16         public ModelItem Key { get; set; }
17
18         public ModelItem OldValue { get; set; }
19
20         public ModelItem NewValue { get; set; }
21
22         public ModelTreeManager ModelTreeManager { get; set; }
23
24
25         public override string Description
26         {
27             get 
28             {
29                 return SR.DictionaryEditEditingScopeDescription;
30             }
31         }
32
33         public override bool Apply()
34         {
35             ModelItem oldValue = this.Dictionary[this.Key];
36             if ((oldValue == null && this.NewValue == null) ||
37                (oldValue != null && this.NewValue != null && oldValue.GetCurrentValue().Equals(this.NewValue.GetCurrentValue())))
38             {
39                 return false;
40             }
41
42             ((ModelItemDictionaryImpl)this.Dictionary).EditCore(this.Key, this.NewValue);
43
44             ModelChangeInfo changeInfo = ModelChangeInfoImpl.CreateDictionaryValueChanged(this.Dictionary, this.Key, this.OldValue, this.NewValue);
45
46             if (this.OldValue != null)
47             {
48                 this.ModelTreeManager.modelService.OnModelItemRemoved(this.OldValue, changeInfo);
49                 changeInfo = null;
50             }
51             if (this.NewValue != null)
52             {
53                 this.ModelTreeManager.modelService.OnModelItemAdded(this.NewValue, changeInfo);
54             }
55             return true;
56         }
57
58
59
60         public override Change GetInverse()
61         {
62             return new DictionaryEditChange()
63                 {
64                     Dictionary = this.Dictionary,
65                     Key = this.Key,
66                     OldValue = this.NewValue,
67                     NewValue = this.OldValue,
68                     ModelTreeManager = this.ModelTreeManager,
69                 };
70         }
71     }
72 }