[corlib] Avoid unnecessary ephemeron array resizes
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / ModelItemKeyValuePair.cs
1 //-----------------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //-----------------------------------------------------------------------------
4
5 namespace System.Activities.Presentation
6 {
7     using System.Collections.ObjectModel;
8     using System.Collections.Generic;
9     using System.Runtime;
10
11     class ModelItemKeyValuePair<TKey, TValue>
12     {
13         internal DictionaryItemsCollection<TKey, TValue> collection;
14
15         TKey key;
16
17         TValue value;
18
19         public ModelItemKeyValuePair()
20         {
21         }
22
23         public ModelItemKeyValuePair(TKey key, TValue value)
24         {
25             this.key = key;
26             this.value = value;
27         }
28
29         [Fx.Tag.KnownXamlExternal]
30         public TKey Key
31         {
32             get
33             {
34                 return this.key;
35             }
36             set
37             {
38                 if (this.collection != null)
39                 {
40                     this.collection.PreUpdateKey(this.key, value);
41                 }
42                 this.key = value;
43                 if (this.collection != null)
44                 {
45                     this.collection.PostUpdateKey();
46                 }
47             }
48         }
49
50         [Fx.Tag.KnownXamlExternal]
51         public TValue Value
52         {
53             get
54             {
55                 return this.value;
56             }
57             set
58             {
59                 if (this.collection != null)
60                 {
61                     this.collection.UpdateValue(this.key, value);
62                 }
63                 this.value = value;
64             }
65         }
66     }
67 }