[NUI] Fix build warning CA1062 (#2234)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / KeyValue.cs
1 /*
2  * Copyright(c) 2019 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 using System;
19 using Tizen.NUI.Binding;
20
21 namespace Tizen.NUI
22 {
23     /// <summary>
24     /// KeyValue class.
25     /// </summary>
26     public class KeyValue
27     {
28         /// <summary>
29         /// Int key.
30         /// </summary>
31         public int? KeyInt = null;
32
33         /// <summary>
34         /// String key.
35         /// </summary>
36         public string KeyString = null;
37
38         /// <summary>
39         /// True value.
40         /// </summary>
41         public PropertyValue TrueValue = null;
42
43         private string _key = null;
44         private object _originalValue = null;
45         private object _originalKey = null;
46
47         /// <summary>
48         /// Default Constructor.
49         /// </summary>
50         public KeyValue()
51         { }
52
53         /// <summary>
54         /// Key property.
55         /// </summary>
56         public string Key
57         {
58             get
59             {
60                 return _key;
61             }
62             set
63             {
64                 _key = value;
65                 ParseKey(value);
66             }
67         }
68
69         /// <summary>
70         /// OriginalKey property.
71         /// </summary>
72         /// <exception cref="ArgumentNullException"> Thrown when value is null. </exception>
73         public object OriginalKey
74         {
75             get
76             {
77                 return _originalKey;
78             }
79             set
80             {
81                 if (null == value)
82                 {
83                     throw new ArgumentNullException(nameof(value));
84                 }
85
86                 _originalKey = value;
87                 if (value is int || value is Int32)
88                 {
89                     KeyInt = (int)value;
90                 }
91                 else if (value is string)
92                 {
93                     KeyString = value.ToString();
94                 }
95                 else if (value.GetType().Equals(typeof(int)) || value.GetType().Equals(typeof(Int32)))
96                 {
97                     KeyInt = (int)value;
98                 }
99                 else if (value.GetType().Equals(typeof(string)))
100                 {
101                     KeyString = value.ToString();
102                 }
103             }
104         }
105
106         /// <summary>
107         /// Value property.
108         /// </summary>
109         public object Value
110         {
111             get
112             {
113                 return _originalValue;
114             }
115             set
116             {
117                 _originalValue = value;
118                 TrueValue = PropertyValue.CreateFromObject(value);
119             }
120         }
121
122         /// <summary>
123         /// IntergerValue property.
124         /// </summary>
125         public int IntergerValue
126         {
127             set
128             {
129                 TrueValue = new PropertyValue(value);
130             }
131         }
132
133         /// <summary>
134         /// BooleanValue property.
135         /// </summary>
136         public bool BooleanValue
137         {
138             set
139             {
140                 TrueValue = new PropertyValue(value);
141             }
142         }
143
144         /// <summary>
145         /// SingleValue property.
146         /// </summary>
147         public float SingleValue
148         {
149             set
150             {
151                 TrueValue = new PropertyValue(value);
152             }
153         }
154
155         /// <summary>
156         /// StringValue property.
157         /// </summary>
158         public string StringValue
159         {
160             set
161             {
162                 TrueValue = new PropertyValue(value);
163             }
164         }
165
166         /// <summary>
167         /// Vector2Value property.
168         /// </summary>
169         public Vector2 Vector2Value
170         {
171             set
172             {
173                 TrueValue = new PropertyValue(value);
174             }
175         }
176
177         /// <summary>
178         /// Vector3Value property.
179         /// </summary>
180         public Vector3 Vector3Value
181         {
182             set
183             {
184                 TrueValue = new PropertyValue(value);
185             }
186         }
187
188         /// <summary>
189         /// Vector4Value property.
190         /// </summary>
191         public Vector4 Vector4Value
192         {
193             set
194             {
195                 TrueValue = new PropertyValue(value);
196             }
197         }
198
199         /// <summary>
200         /// PositionValue property.
201         /// </summary>
202         public Position PositionValue
203         {
204             set
205             {
206                 TrueValue = new PropertyValue(value);
207             }
208         }
209
210         /// <summary>
211         /// Position2DValue property.
212         /// </summary>
213         public Position2D Position2DValue
214         {
215             set
216             {
217                 TrueValue = new PropertyValue(value);
218             }
219         }
220
221         /// <summary>
222         /// SizeValue property.
223         /// </summary>
224         public Size SizeValue
225         {
226             set
227             {
228                 TrueValue = new PropertyValue(value);
229             }
230         }
231
232         /// <summary>
233         /// Size2DValue property.
234         /// </summary>
235         public Size2D Size2DValue
236         {
237             set
238             {
239                 TrueValue = new PropertyValue(value);
240             }
241         }
242
243         /// <summary>
244         /// ColorValue property.
245         /// </summary>
246         public Color ColorValue
247         {
248             set
249             {
250                 TrueValue = new PropertyValue(value);
251             }
252         }
253
254         /// <summary>
255         /// RectangleValue property.
256         /// </summary>
257         public Rectangle RectangleValue
258         {
259             set
260             {
261                 TrueValue = new PropertyValue(value);
262             }
263         }
264
265         /// <summary>
266         /// RotationValue property.
267         /// </summary>
268         public Rotation RotationValue
269         {
270             set
271             {
272                 TrueValue = new PropertyValue(value);
273             }
274         }
275
276         /// <summary>
277         /// RelativeVector2Value property.
278         /// </summary>
279         public RelativeVector2 RelativeVector2Value
280         {
281             set
282             {
283                 TrueValue = new PropertyValue(value);
284             }
285         }
286
287         /// <summary>
288         /// RelativeVector3Value property.
289         /// </summary>
290         public RelativeVector3 RelativeVector3Value
291         {
292             set
293             {
294                 TrueValue = new PropertyValue(value);
295             }
296         }
297
298         /// <summary>
299         /// RelativeVector4Value property.
300         /// </summary>
301         public RelativeVector4 RelativeVector4Value
302         {
303             set
304             {
305                 TrueValue = new PropertyValue(value);
306             }
307         }
308
309         /// <summary>
310         /// ExtentsValue property.
311         /// </summary>
312         public Extents ExtentsValue
313         {
314             set
315             {
316                 TrueValue = new PropertyValue(value);
317             }
318         }
319
320         /// <summary>
321         /// PropertyArrayValue property.
322         /// </summary>
323         public PropertyArray PropertyArrayValue
324         {
325             set
326             {
327                 TrueValue = new PropertyValue(value);
328             }
329         }
330
331         /// <summary>
332         /// PropertyMapValue property.
333         /// </summary>
334         public PropertyMap PropertyMapValue
335         {
336             set
337             {
338                 TrueValue = new PropertyValue(value);
339             }
340         }
341
342         private void ParseKey(string key)
343         {
344             int v = -1;
345             if (VisualExtension.KeyDictionary.ContainsKey(key))
346             {
347                 VisualExtension.KeyDictionary.TryGetValue(key, out v);
348                 KeyInt = v;
349             }
350             else
351             {
352                 KeyString = Key;
353             }
354         }
355     }
356 }