[corlib] Avoid unnecessary ephemeron array resizes
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Base / Core / PropertyEditing / DependencyPropertyValueSource.cs
1 namespace System.Activities.Presentation.PropertyEditing {
2     using System;
3
4     using System.Runtime;
5
6     /// <summary>
7     /// Concrete implementation of PropertyValueSource for a PropertyEntry that represents a Dependency Property
8     /// </summary>
9     [Fx.Tag.XamlVisible(false)]
10     public class DependencyPropertyValueSource : PropertyValueSource
11     {
12
13         private static DependencyPropertyValueSource _dataBound;
14         private static DependencyPropertyValueSource _systemResource;
15         private static DependencyPropertyValueSource _localDynamicResource;
16         private static DependencyPropertyValueSource _localStaticResource;
17         private static DependencyPropertyValueSource _templateBinding;
18         private static DependencyPropertyValueSource _customMarkupExtension;
19         private static DependencyPropertyValueSource _local;
20         private static DependencyPropertyValueSource _defaultValue;
21         private static DependencyPropertyValueSource _inherited;
22
23         private readonly ValueSource _source;
24
25         /// <summary>
26         /// The property is set to a value that is a data binding.
27         /// </summary>
28         public static DependencyPropertyValueSource DataBound {
29             get {
30                 if (_dataBound == null) _dataBound = new DependencyPropertyValueSource(ValueSource.DataBound);
31                 return _dataBound;
32             }
33         }
34
35         /// <summary>
36         /// The property is set to a system resource.
37         /// </summary>
38         public static DependencyPropertyValueSource SystemResource {
39             get {
40                 if (_systemResource == null) _systemResource = new DependencyPropertyValueSource(ValueSource.SystemResource);
41                 return _systemResource;
42             }
43         }
44
45         /// <summary>
46         /// The property is set to a DynamicResource reference.
47         /// </summary>
48         public static DependencyPropertyValueSource LocalDynamicResource {
49             get {
50                 if (_localDynamicResource == null) _localDynamicResource = new DependencyPropertyValueSource(ValueSource.LocalDynamicResource);
51                 return _localDynamicResource;
52             }
53         }
54
55         /// <summary>
56         /// The property is set to a StaticResource reference.
57         /// </summary>
58         public static DependencyPropertyValueSource LocalStaticResource {
59             get {
60                 if (_localStaticResource == null) _localStaticResource = new DependencyPropertyValueSource(ValueSource.LocalStaticResource);
61                 return _localStaticResource;
62             }
63         }
64
65         /// <summary>
66         /// The property is set to a TemplateBinding markup extension.
67         /// </summary>
68         public static DependencyPropertyValueSource TemplateBinding {
69             get {
70                 if (_templateBinding == null) _templateBinding = new DependencyPropertyValueSource(ValueSource.TemplateBinding);
71                 return _templateBinding;
72             }
73         }
74
75         /// <summary>
76         /// The property is set to a custom markup extension.
77         /// </summary>
78         public static DependencyPropertyValueSource CustomMarkupExtension {
79             get {
80                 if (_customMarkupExtension == null) _customMarkupExtension = new DependencyPropertyValueSource(ValueSource.CustomMarkupExtension);
81                 return _customMarkupExtension;
82             }
83         }
84
85         /// <summary>
86         /// The property is set to a local value.
87         /// </summary>
88         public static DependencyPropertyValueSource Local {
89             get {
90                 if (_local == null) _local = new DependencyPropertyValueSource(ValueSource.Local);
91                 return _local;
92             }
93         }
94
95         /// <summary>
96         /// The property is set to its default value (ie. it does not have a value set in XAML and 
97         /// it's not inheriting any value from its parent)
98         /// </summary>
99         public static DependencyPropertyValueSource DefaultValue {
100             get {
101                 if (_defaultValue == null) _defaultValue = new DependencyPropertyValueSource(ValueSource.DefaultValue);
102                 return _defaultValue;
103             }
104         }
105
106         /// <summary>
107         /// The property is inherited from a parent property.
108         /// </summary>
109         public static DependencyPropertyValueSource Inherited {
110             get {
111                 if (_inherited == null) _inherited = new DependencyPropertyValueSource(ValueSource.Inherited);
112                 return _inherited;
113             }
114         }
115
116         private DependencyPropertyValueSource(ValueSource source) {
117             _source = source;
118         }
119
120         /// <summary>
121         /// Read-only property that returns true if the property is set to an expression 
122         /// i.e. (DataBound, LocalDynamicResource, LocalStaticResource, SystemResource, TemplateBinding or
123         /// CustomMarkupExtension)
124         /// </summary>
125         public bool IsExpression {
126             get {
127                 return _source == ValueSource.DataBound
128                     || _source == ValueSource.LocalDynamicResource
129                     || _source == ValueSource.LocalStaticResource
130                     || _source == ValueSource.SystemResource
131                     || _source == ValueSource.TemplateBinding
132                     || _source == ValueSource.CustomMarkupExtension;
133             }
134         }
135
136         /// <summary>
137         /// Read-only property that returns true if the property is set to a system or local resource
138         /// </summary>
139         public bool IsResource {
140             get {
141                 return _source == ValueSource.SystemResource
142                     || _source == ValueSource.LocalDynamicResource
143                     || _source == ValueSource.LocalStaticResource;
144             }
145         }
146
147         /// <summary>
148         /// Read-only property that returns true if the property is set to a data binding expression.
149         /// </summary>
150         public bool IsDataBound {
151             get { return _source == ValueSource.DataBound; }
152         }
153
154         /// <summary>
155         /// Read-only property that returns true if the property is set to a system resource
156         /// </summary>
157         public bool IsSystemResource {
158             get { return _source == ValueSource.SystemResource; }
159         }
160
161         /// <summary>
162         /// Read-only property that returns true if the property is set to a DynamicResource
163         /// </summary>
164         public bool IsLocalResource {
165             get {
166                 return _source == ValueSource.LocalDynamicResource
167                 || _source == ValueSource.LocalStaticResource;
168             }
169         }
170
171         /// <summary>
172         /// Read-only property that returns true if the property is set to a TemplateBinding markup extension
173         /// </summary>
174         public bool IsTemplateBinding {
175             get { return _source == ValueSource.TemplateBinding; }
176         }
177
178         /// <summary>
179         /// Read-only property that returns true if the property is set to a custom markup extension.
180         /// </summary>
181         public bool IsCustomMarkupExtension {
182             get { return _source == ValueSource.CustomMarkupExtension; }
183         }
184
185         /// <summary>
186         /// Read-only property that returns true if the property is set to a local value.
187         /// </summary>
188         public bool IsLocal {
189             get { return _source == ValueSource.Local; }
190         }
191
192         /// <summary>
193         /// Read-only property that returns true if the property is set to its default value 
194         /// (ie. it does not have a value set in XAML and it's not inheriting any value from
195         /// its parent)
196         /// </summary>
197         public bool IsDefaultValue {
198             get { return _source == ValueSource.DefaultValue; }
199         }
200
201         /// <summary>
202         /// Read-only property that returns true if the property is inherited.
203         /// </summary>
204         public bool IsInherited {
205             get { return _source == ValueSource.Inherited; }
206         }
207
208         private enum ValueSource {
209             DataBound,
210             SystemResource,
211             LocalDynamicResource,
212             LocalStaticResource,
213             TemplateBinding,
214             CustomMarkupExtension,
215             Local,
216             DefaultValue,
217             Inherited
218         }
219     }
220 }