[NUI]public the converter for Xaml (#2837)
authorAdunFang <30402408+AdunFang@users.noreply.github.com>
Thu, 8 Apr 2021 12:50:53 +0000 (20:50 +0800)
committerhuiyueun <35286162+huiyueun@users.noreply.github.com>
Tue, 20 Apr 2021 06:13:00 +0000 (15:13 +0900)
* [NUI]public the converter for Xaml

* [NUI]public Vector3 converter

* [NUI] remove unneccessary modification

* [NUI] Fix build warning of Xaml

* [NUI] Fix build warning of Xaml

* [NUI] Remove unused code

Co-authored-by: Jiyun Yang <ji.yang@samsung.com>
src/Tizen.NUI/src/internal/XamlBinding/PositionTypeConverter.cs
src/Tizen.NUI/src/internal/XamlBinding/RectangleTypeConverter.cs
src/Tizen.NUI/src/internal/XamlBinding/RotationTypeConverter.cs
src/Tizen.NUI/src/internal/XamlBinding/TypeTypeConverter.cs
src/Tizen.NUI/src/internal/XamlBinding/VectorTypeConverter.cs

index bb10bed..ffd9207 100755 (executable)
@@ -21,11 +21,16 @@ using System.Reflection;
 using System.Globalization;
 
 using Tizen.NUI;
+using System.ComponentModel;
 
 namespace Tizen.NUI.Binding
 {
-    internal class PositionTypeConverter : TypeConverter
+    //Internal used, will never open
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class PositionTypeConverter : TypeConverter
     {
+        //Internal used, will never open
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public override object ConvertFromInvariantString(string value)
         {
             if (value != null)
@@ -87,24 +92,46 @@ namespace Tizen.NUI.Binding
             throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Position)}");
         }
 
+        //Internal used, will never open
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public override string ConvertToString(object value)
         {
-            Position position = (Position)value;
-            return position.X.ToString() + " " + position.Y.ToString() + " " + position.Z.ToString();
+            Position position = value as Position;
+            if (null != position)
+            {
+                return position.X.ToString() + " " + position.Y.ToString() + " " + position.Z.ToString();
+            }
+            else
+            {
+                return null;
+            }
         }
     }
 
-    internal class Position2DTypeConverter : TypeConverter
+    //Internal used, will never open
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class Position2DTypeConverter : TypeConverter
     {
+        //Internal used, will never open
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public override object ConvertFromInvariantString(string value)
         {
             return Position2D.ConvertFromString(value);
         }
 
+        //Internal used, will never open
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public override string ConvertToString(object value)
         {
-            Position2D position = (Position2D)value;
-            return position.X.ToString() + " " + position.Y.ToString();
+            Position2D position = value as Position2D;
+            if (null != position)
+            {
+                return position.X.ToString() + " " + position.Y.ToString();
+            }
+            else
+            {
+                return null;
+            }
         }
     }
 }
index b2b0aa8..51f665c 100755 (executable)
  */
 
 using System;
+using System.ComponentModel;
 using System.Globalization;
 
 using Tizen.NUI;
 
 namespace Tizen.NUI.Binding
 {
+    //Internal used, will never open
     [Xaml.ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.RectangleTypeConverter")]
     [Xaml.TypeConversion(typeof(Rectangle))]
-    internal class RectangleTypeConverter : TypeConverter
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class RectangleTypeConverter : TypeConverter
     {
+        //Internal used, will never open
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public override object ConvertFromInvariantString(string value)
         {
             if (value != null)
@@ -40,10 +45,19 @@ namespace Tizen.NUI.Binding
             throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", value, typeof(Rectangle)));
         }
 
+        //Internal used, will never open
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public override string ConvertToString(object value)
         {
-            Rectangle rec = (Rectangle)value;
-            return rec.X.ToString() + " " + rec.Y.ToString() + " " + rec.Width.ToString() + " " + rec.Height.ToString();
+            Rectangle rect = value as Rectangle;
+            if (null != rect)
+            {
+                return rect.X.ToString() + " " + rect.Y.ToString() + " " + rect.Width.ToString() + " " + rect.Height.ToString();
+            }
+            else
+            {
+                return null;
+            }
         }
     }
 }
index 53ed1da..56ef254 100755 (executable)
  */
 
 using System;
+using System.ComponentModel;
 using System.Globalization;
 
 namespace Tizen.NUI.Binding
 {
-    internal class RotationTypeConverter : TypeConverter
+    //Internal used, will never open
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class RotationTypeConverter : TypeConverter
     {
+        //Internal used, will never open
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public override object ConvertFromInvariantString(string value)
         {
             // public Rotation(Radian radian(float), Vector3 vector3)
@@ -43,7 +48,9 @@ namespace Tizen.NUI.Binding
                         if (radianOrDegree == "D" || radianOrDegree == "DEGREE")
                         {
                             // Orientation="D:23, 0, 0, 1"
-                            radian = new Radian(new Degree(Single.Parse(head[1].Trim(), CultureInfo.InvariantCulture)));
+                            var degree = new Degree(Single.Parse(head[1].Trim(), CultureInfo.InvariantCulture));
+                            radian = new Radian(degree);
+                            degree.Dispose();
                         }
                         else if (radianOrDegree == "R" || radianOrDegree == "RADIAN")
                         {
@@ -65,17 +72,22 @@ namespace Tizen.NUI.Binding
                     Vector3 vector3 = new Vector3(Single.Parse(parts[1].Trim(), CultureInfo.InvariantCulture),
                                                   Single.Parse(parts[2].Trim(), CultureInfo.InvariantCulture),
                                                   Single.Parse(parts[3].Trim(), CultureInfo.InvariantCulture));
-                    return new Rotation(radian, vector3);
+                    var ret = new Rotation(radian, vector3);
+                    radian?.Dispose();
+                    vector3.Dispose();
+                    return ret;
                 }
             }
 
             throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Rotation)}");
         }
 
+        //Internal used, will never open
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public override string ConvertToString(object value)
         {
-            Rotation rotation = (Rotation)value;
-            return rotation.ToString();
+            Rotation rotation = value as Rotation;
+            return rotation?.ToString();
         }
     }
 }
index 450bc2f..d122f3d 100755 (executable)
  */
 
 using System;
+using System.ComponentModel;
 using System.Globalization;
 using Tizen.NUI.Xaml;
 
 namespace Tizen.NUI.Binding
 {
+    /// Internal use, will never open
+    [EditorBrowsable(EditorBrowsableState.Never)]
     [Xaml.ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.TypeTypeConverter")]
     [Xaml.TypeConversion(typeof(Type))]
-    internal sealed class TypeTypeConverter : TypeConverter, IExtendedTypeConverter
+    public sealed class TypeTypeConverter : TypeConverter, IExtendedTypeConverter
     {
         [Obsolete("IExtendedTypeConverter.ConvertFrom is obsolete as of version 2.2.0. Please use ConvertFromInvariantString (string, IServiceProvider) instead.")]
         object IExtendedTypeConverter.ConvertFrom(CultureInfo culture, object value, IServiceProvider serviceProvider)
@@ -42,6 +45,8 @@ namespace Tizen.NUI.Binding
             return typeResolver.Resolve(value, serviceProvider);
         }
 
+        /// Internal use, will never open
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public override object ConvertFromInvariantString(string value)
         {
             throw new NotImplementedException();
index 626eb45..cd13715 100755 (executable)
@@ -21,11 +21,16 @@ using System.Reflection;
 using System.Globalization;
 
 using Tizen.NUI;
+using System.ComponentModel;
 
 namespace Tizen.NUI.Binding
 {
-    internal class Vector2TypeConverter : TypeConverter
+    //Internal used, will never open
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class Vector2TypeConverter : TypeConverter
     {
+        //Internal used, will never open
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public override object ConvertFromInvariantString(string value)
         {
             if (value != null)
@@ -36,9 +41,11 @@ namespace Tizen.NUI.Binding
             throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Vector2)}");
         }
 
+        //Internal used, will never open
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public override string ConvertToString(object value)
         {
-            return ToString((Vector2)value);
+            return ToString(value as Vector2);
         }
 
         internal static Vector2 FromString(string value)
@@ -55,12 +62,23 @@ namespace Tizen.NUI.Binding
 
         internal static string ToString(Vector2 value)
         {
-            return value.X.ToString() + " " + value.Y.ToString();
+            if (null != value)
+            {
+                return value.X.ToString() + " " + value.Y.ToString();
+            }
+            else
+            {
+                return null;
+            }
         }
     }
 
-    internal class Vector3TypeConverter : TypeConverter
+    //Internal used, will never open
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class Vector3TypeConverter : TypeConverter
     {
+        //Internal used, will never open
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public override object ConvertFromInvariantString(string value)
         {
             if (value != null)
@@ -77,15 +95,28 @@ namespace Tizen.NUI.Binding
             throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Vector3)}");
         }
 
+        //Internal used, will never open
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public override string ConvertToString(object value)
         {
-            Vector3 vector = (Vector3)value;
-            return vector.X.ToString() + " " + vector.Y.ToString() + " " + vector.Z.ToString();
+            Vector3 vector = value as Vector3;
+            if (null != vector)
+            {
+                return vector.X.ToString() + " " + vector.Y.ToString() + " " + vector.Z.ToString();
+            }
+            else
+            {
+                return null;
+            }
         }
     }
 
-    internal class Vector4TypeConverter : TypeConverter
+    //Internal used, will never open
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class Vector4TypeConverter : TypeConverter
     {
+        //Internal used, will never open
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public override object ConvertFromInvariantString(string value)
         {
             if (value != null)
@@ -103,15 +134,28 @@ namespace Tizen.NUI.Binding
             throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Vector4)}");
         }
 
+        //Internal used, will never open
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public override string ConvertToString(object value)
         {
-            Vector4 vector = (Vector4)value;
-            return vector.X.ToString() + " " + vector.Y.ToString() + " " + vector.Z.ToString() + " " + vector.W.ToString();
+            Vector4 vector = value as Vector4;
+            if (null != vector)
+            {
+                return vector.X.ToString() + " " + vector.Y.ToString() + " " + vector.Z.ToString() + " " + vector.W.ToString();
+            }
+            else
+            {
+                return null;
+            }
         }
     }
 
-    internal class RelativeVector2TypeConverter : TypeConverter
+    //Internal used, will never open
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class RelativeVector2TypeConverter : TypeConverter
     {
+        //Internal used, will never open
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public override object ConvertFromInvariantString(string value)
         {
             if (value != null)
@@ -127,15 +171,28 @@ namespace Tizen.NUI.Binding
             throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(RelativeVector2)}");
         }
 
+        //Internal used, will never open
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public override string ConvertToString(object value)
         {
-            RelativeVector2 vector = (RelativeVector2)value;
-            return vector.X.ToString() + " " + vector.Y.ToString();
+            RelativeVector2 vector = value as RelativeVector2;
+            if (null != vector)
+            {
+                return vector.X.ToString() + " " + vector.Y.ToString();
+            }
+            else
+            {
+                return null;
+            }
         }
     }
 
-    internal class RelativeVector3TypeConverter : TypeConverter
+    //Internal used, will never open
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class RelativeVector3TypeConverter : TypeConverter
     {
+        //Internal used, will never open
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public override object ConvertFromInvariantString(string value)
         {
             if (value != null)
@@ -152,15 +209,28 @@ namespace Tizen.NUI.Binding
             throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(RelativeVector3)}");
         }
 
+        //Internal used, will never open
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public override string ConvertToString(object value)
         {
-            RelativeVector3 vector = (RelativeVector3)value;
-            return vector.X.ToString() + " " + vector.Y.ToString() + " " + vector.Z.ToString();
+            RelativeVector3 vector = value as RelativeVector3;
+            if (null != vector)
+            {
+                return vector.X.ToString() + " " + vector.Y.ToString() + " " + vector.Z.ToString();
+            }
+            else
+            {
+                return null;
+            }
         }
     }
 
-    internal class RelativeVector4TypeConverter : TypeConverter
+    //Internal used, will never open
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class RelativeVector4TypeConverter : TypeConverter
     {
+        //Internal used, will never open
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public override object ConvertFromInvariantString(string value)
         {
             if (value != null)
@@ -178,10 +248,19 @@ namespace Tizen.NUI.Binding
             throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(RelativeVector4)}");
         }
 
+        //Internal used, will never open
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public override string ConvertToString(object value)
         {
-            RelativeVector4 vector = (RelativeVector4)value;
-            return vector.X.ToString() + " " + vector.Y.ToString() + " " + vector.Z.ToString() + " " + vector.W.ToString(); ;
+            RelativeVector4 vector = value as RelativeVector4;
+            if (null != vector)
+            {
+                return vector.X.ToString() + " " + vector.Y.ToString() + " " + vector.Z.ToString() + " " + vector.W.ToString();
+            }
+            else
+            {
+                return null;
+            }
         }
     }
 }