Follow formatting NUI
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / XamlBinding / RotationTypeConverter.cs
1 using System;
2 using System.Globalization;
3
4 namespace Tizen.NUI.Binding
5 {
6     internal class RotationTypeConverter : TypeConverter
7     {
8         public override object ConvertFromInvariantString(string value)
9         {
10             // public Rotation(Radian radian(float), Vector3 vector3)
11             // Default: <View Orientation="45.0,12,13,0" />
12             // Oritation="D:23, 0, 0, 1"
13             // Oritation="R:23, 0, 0, 1"
14             if (value != null)
15             {
16                 string[] parts = value.Split(',');
17                 if (parts.Length == 4)
18                 {
19                     bool useDefault = true;
20                     Radian radian = null;
21                     string[] head = parts[0].Trim().Split(':');
22                     if (head.Length == 2)
23                     {
24                         useDefault = false;
25                         string radianOrDegree = head[0].Trim().ToLowerInvariant();
26                         if (radianOrDegree == "d" || radianOrDegree == "degree")
27                         {
28                             // Oritation="D:23, 0, 0, 1"
29                             radian = new Radian(new Degree(Single.Parse(head[1].Trim(), CultureInfo.InvariantCulture)));
30                         }
31                         else if (radianOrDegree == "r" || radianOrDegree == "radian")
32                         {
33                             // Oritation="R:23, 0, 0, 1"
34                             radian = new Radian(Single.Parse(head[1].Trim(), CultureInfo.InvariantCulture));
35                         }
36                         else
37                         {
38                             throw new InvalidOperationException($"Cannot convert the first parameter \"{value}\" into Radian of {typeof(Rotation)}");
39                         }
40                     }
41
42                     if (useDefault)
43                     {
44                         // Default: <View Orientation="45.0,12,13,0" />
45                         radian = new Radian(Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture));
46                     }
47
48                     Vector3 vector3 = new Vector3(Single.Parse(parts[1].Trim(), CultureInfo.InvariantCulture),
49                                                   Single.Parse(parts[2].Trim(), CultureInfo.InvariantCulture),
50                                                   Single.Parse(parts[3].Trim(), CultureInfo.InvariantCulture));
51                     return new Rotation(radian, vector3);
52                 }
53             }
54
55             throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Rotation)}");
56         }
57
58         public override string ConvertToString(object value)
59         {
60             Rotation rotation = (Rotation)value;
61             return rotation.ToString();
62         }
63     }
64 }