d5277159a4f370dacfee9724d7ab17ce54670fc6
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / XamlBinding / SizeTypeConverter.cs
1 using System;
2 using System.Linq;
3 using System.Reflection;
4 using System.Globalization;
5
6 using Tizen.NUI;
7 using Tizen.NUI.Xaml;
8
9 namespace Tizen.NUI.Binding
10 {
11     [ProvideCompiledAttribute("Tizen.NUI.Xaml.Core.XamlC.Size2DTypeConverter")]
12     internal class SizeTypeConverter : TypeConverter
13     {
14         public override object ConvertFromInvariantString(string value)
15         {
16             if (value != null)
17             {
18                 string[] parts = value.Split(',');
19                 if (parts.Length == 3)
20                 {
21                     int x = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[0].Trim());
22                     int y = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[1].Trim());
23                     int z = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[2].Trim());
24                     return new Size(x, y, z);
25                 }
26             }
27
28             throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Size)}");
29         }
30     }
31
32     [ProvideCompiledAttribute("Tizen.NUI.Xaml.Core.XamlC.Size2DTypeConverter")]
33     internal class Size2DTypeConverter : TypeConverter
34     {
35         public override object ConvertFromInvariantString(string value)
36         {
37             if (value != null)
38             {
39                 string[] parts = value.Split(',');
40                 if (parts.Length == 2)
41                 {
42                     int x = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[0].Trim());
43                     int y = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[1].Trim());
44                     return new Size2D(x, y);
45                 }
46             }
47
48             throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Size2D)}");
49         }
50     }
51 }