2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using System.Collections.Generic;
20 using System.Reflection;
21 using System.Runtime.InteropServices;
22 using Tizen.NUI.Binding;
26 internal static class Extensions
28 public static T GetInstanceSafely<T>(this object wrapper, IntPtr cPtr) where T : BaseHandle
30 HandleRef CPtr = new HandleRef(wrapper, cPtr);
31 T ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as T;
32 Interop.BaseHandle.delete_BaseHandle(CPtr);
33 CPtr = new HandleRef(null, IntPtr.Zero);
37 public static string GetValueString(this PropertyInfo property, object obj, Type propertyType)
40 object value = property.GetValue(obj);
41 if (null == value) return ret;
43 TypeConverter typeConverter;
44 if (WellKnownConvertTypes.TryGetValue(propertyType, out typeConverter))
46 ret = typeConverter.ConvertToString(value);
50 ret = value.ToString();
55 static readonly Dictionary<Type, TypeConverter> WellKnownConvertTypes = new Dictionary<Type, TypeConverter>
57 //{ typeof(Uri), new UriTypeConverter() },
58 { typeof(Color), new ColorTypeConverter() },
59 { typeof(Size2D), new Size2DTypeConverter() },
60 { typeof(Position2D), new Position2DTypeConverter() },
61 { typeof(Size), new SizeTypeConverter() },
62 { typeof(Position), new PositionTypeConverter() },
63 { typeof(Rectangle), new RectangleTypeConverter() },
64 { typeof(Rotation), new RotationTypeConverter() },
65 { typeof(Vector2), new Vector2TypeConverter() },
66 { typeof(Vector3), new Vector3TypeConverter() },
67 { typeof(Vector4), new Vector4TypeConverter() },
68 { typeof(RelativeVector2), new RelativeVector2TypeConverter() },
69 { typeof(RelativeVector3), new RelativeVector3TypeConverter() },
70 { typeof(RelativeVector4), new RelativeVector4TypeConverter() },