[NUI] Fix Dispose warning error[CA1001] (#2130)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / KeyValue.cs
1 /*
2  * Copyright(c) 2020 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 System.ComponentModel;
20 using Tizen.NUI.Binding;
21
22 namespace Tizen.NUI
23 {
24     /// <summary>
25     /// KeyValue class.
26     /// </summary>
27     public class KeyValue : Disposable
28     {
29         /// <summary>
30         /// Int key.
31         /// </summary>
32         public int? KeyInt = null;
33
34         /// <summary>
35         /// String key.
36         /// </summary>
37         public string KeyString = null;
38
39         /// <summary>
40         /// True value.
41         /// </summary>
42         public PropertyValue TrueValue = null;
43
44         private string _key = null;
45         private object _originalValue = null;
46         private object _originalKey = null;
47
48         /// <summary>
49         /// Default Constructor.
50         /// </summary>
51         public KeyValue()
52         { }
53
54         /// <summary>   
55         /// destructor. This is HiddenAPI. recommended not to use in public.    
56         /// </summary>  
57         [EditorBrowsable(EditorBrowsableState.Never)]
58         ~KeyValue()
59         {
60             Dispose();
61         }
62
63         /// <summary>
64         /// Key property.
65         /// </summary>
66         public string Key
67         {
68             get
69             {
70                 return _key;
71             }
72             set
73             {
74                 _key = value;
75                 ParseKey(value);
76             }
77         }
78
79         /// <summary>
80         /// OriginalKey property.
81         /// </summary>
82         public object OriginalKey
83         {
84             get
85             {
86                 return _originalKey;
87             }
88             set
89             {
90                 _originalKey = value;
91                 if (value is int || value is Int32)
92                 {
93                     KeyInt = (int)value;
94                 }
95                 else if (value is string)
96                 {
97                     KeyString = value.ToString();
98                 }
99                 else if (value.GetType().Equals(typeof(int)) || value.GetType().Equals(typeof(Int32)))
100                 {
101                     KeyInt = (int)value;
102                 }
103                 else if (value.GetType().Equals(typeof(string)))
104                 {
105                     KeyString = value.ToString();
106                 }
107             }
108         }
109
110         /// <summary>
111         /// Value property.
112         /// </summary>
113         public object Value
114         {
115             get
116             {
117                 return _originalValue;
118             }
119             set
120             {
121                 _originalValue = value;
122                 TrueValue = PropertyValue.CreateFromObject(value);
123             }
124         }
125
126         /// <summary>
127         /// IntergerValue property.
128         /// </summary>
129         public int IntergerValue
130         {
131             set
132             {
133                 TrueValue = new PropertyValue(value);
134             }
135         }
136
137         /// <summary>
138         /// BooleanValue property.
139         /// </summary>
140         public bool BooleanValue
141         {
142             set
143             {
144                 TrueValue = new PropertyValue(value);
145             }
146         }
147
148         /// <summary>
149         /// SingleValue property.
150         /// </summary>
151         public float SingleValue
152         {
153             set
154             {
155                 TrueValue = new PropertyValue(value);
156             }
157         }
158
159         /// <summary>
160         /// StringValue property.
161         /// </summary>
162         public string StringValue
163         {
164             set
165             {
166                 TrueValue = new PropertyValue(value);
167             }
168         }
169
170         /// <summary>
171         /// Vector2Value property.
172         /// </summary>
173         public Vector2 Vector2Value
174         {
175             set
176             {
177                 TrueValue = new PropertyValue(value);
178             }
179         }
180
181         /// <summary>
182         /// Vector3Value property.
183         /// </summary>
184         public Vector3 Vector3Value
185         {
186             set
187             {
188                 TrueValue = new PropertyValue(value);
189             }
190         }
191
192         /// <summary>
193         /// Vector4Value property.
194         /// </summary>
195         public Vector4 Vector4Value
196         {
197             set
198             {
199                 TrueValue = new PropertyValue(value);
200             }
201         }
202
203         /// <summary>
204         /// PositionValue property.
205         /// </summary>
206         public Position PositionValue
207         {
208             set
209             {
210                 TrueValue = new PropertyValue(value);
211             }
212         }
213
214         /// <summary>
215         /// Position2DValue property.
216         /// </summary>
217         public Position2D Position2DValue
218         {
219             set
220             {
221                 TrueValue = new PropertyValue(value);
222             }
223         }
224
225         /// <summary>
226         /// SizeValue property.
227         /// </summary>
228         public Size SizeValue
229         {
230             set
231             {
232                 TrueValue = new PropertyValue(value);
233             }
234         }
235
236         /// <summary>
237         /// Size2DValue property.
238         /// </summary>
239         public Size2D Size2DValue
240         {
241             set
242             {
243                 TrueValue = new PropertyValue(value);
244             }
245         }
246
247         /// <summary>
248         /// ColorValue property.
249         /// </summary>
250         public Color ColorValue
251         {
252             set
253             {
254                 TrueValue = new PropertyValue(value);
255             }
256         }
257
258         /// <summary>
259         /// RectangleValue property.
260         /// </summary>
261         public Rectangle RectangleValue
262         {
263             set
264             {
265                 TrueValue = new PropertyValue(value);
266             }
267         }
268
269         /// <summary>
270         /// RotationValue property.
271         /// </summary>
272         public Rotation RotationValue
273         {
274             set
275             {
276                 TrueValue = new PropertyValue(value);
277             }
278         }
279
280         /// <summary>
281         /// RelativeVector2Value property.
282         /// </summary>
283         public RelativeVector2 RelativeVector2Value
284         {
285             set
286             {
287                 TrueValue = new PropertyValue(value);
288             }
289         }
290
291         /// <summary>
292         /// RelativeVector3Value property.
293         /// </summary>
294         public RelativeVector3 RelativeVector3Value
295         {
296             set
297             {
298                 TrueValue = new PropertyValue(value);
299             }
300         }
301
302         /// <summary>
303         /// RelativeVector4Value property.
304         /// </summary>
305         public RelativeVector4 RelativeVector4Value
306         {
307             set
308             {
309                 TrueValue = new PropertyValue(value);
310             }
311         }
312
313         /// <summary>
314         /// ExtentsValue property.
315         /// </summary>
316         public Extents ExtentsValue
317         {
318             set
319             {
320                 TrueValue = new PropertyValue(value);
321             }
322         }
323
324         /// <summary>
325         /// PropertyArrayValue property.
326         /// </summary>
327         public PropertyArray PropertyArrayValue
328         {
329             set
330             {
331                 TrueValue = new PropertyValue(value);
332             }
333         }
334
335         /// <summary>
336         /// PropertyMapValue property.
337         /// </summary>
338         public PropertyMap PropertyMapValue
339         {
340             set
341             {
342                 TrueValue = new PropertyValue(value);
343             }
344         }
345
346         private void ParseKey(string key)
347         {
348             int v = -1;
349             if (VisualExtension.KeyDictionary.ContainsKey(key))
350             {
351                 VisualExtension.KeyDictionary.TryGetValue(key, out v);
352                 KeyInt = v;
353             }
354             else
355             {
356                 KeyString = Key;
357             }
358         }
359
360         /// <summary>
361         /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
362         /// </summary>
363         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
364         [EditorBrowsable(EditorBrowsableState.Never)]
365         protected override void Dispose(DisposeTypes type)
366         {
367             if (disposed)
368             {
369                 return;
370             }
371
372             TrueValue?.Dispose();
373
374             base.Dispose();
375         }
376     }
377 }