[NUI] Add object dump function (#1239)
authorXianbing Teng <xb.teng@samsung.com>
Tue, 17 Mar 2020 07:14:26 +0000 (15:14 +0800)
committerGitHub <noreply@github.com>
Tue, 17 Mar 2020 07:14:26 +0000 (16:14 +0900)
13 files changed:
src/Tizen.NUI/src/internal/EnumHelper.cs
src/Tizen.NUI/src/internal/Extensions.cs
src/Tizen.NUI/src/internal/XamlBinding/ExtentsTypeConverter.cs
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/VectorTypeConverter.cs
src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs
src/Tizen.NUI/src/public/BaseComponents/ViewPublicMethods.cs
src/Tizen.NUI/src/public/Window.cs
src/Tizen.NUI/src/public/XamlBinding/ColorTypeConverter.cs
src/Tizen.NUI/src/public/XamlBinding/SizeTypeConverter.cs
src/Tizen.NUI/src/public/XamlBinding/TypeConverter.cs

index 4e02d31..a4f2684 100755 (executable)
@@ -72,7 +72,8 @@ namespace Tizen.NUI
                 }
             }
 
-            throw new ArgumentException($"{description} can't be found.", "Description");
+            return (T)type.GetFields(BindingFlags.Public | BindingFlags.Static).FirstOrDefault().GetValue(null);
+            //throw new ArgumentException($"{description} can't be found.", "Description");
         }
 
         /// <summary>
index 7d14503..5a7235f 100755 (executable)
  */
 
 using System;
+using System.Collections.Generic;
+using System.Reflection;
 using System.Runtime.InteropServices;
-using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Binding;
 
 namespace Tizen.NUI
 {
@@ -31,5 +33,41 @@ namespace Tizen.NUI
             CPtr = new HandleRef(null, IntPtr.Zero);
             return ret;
         }
+
+        public static string GetValueString(this PropertyInfo property,  object obj, Type propertyType)
+        {
+            string ret = "";
+            object value = property.GetValue(obj);
+            if (null == value) return ret;
+
+            TypeConverter typeConverter;
+            if (WellKnownConvertTypes.TryGetValue(propertyType, out typeConverter))
+            {
+                ret = typeConverter.ConvertToString(value);
+            }
+            else
+            {
+                ret = value.ToString();
+            }
+            return ret;
+        }
+
+        static readonly Dictionary<Type, TypeConverter> WellKnownConvertTypes = new Dictionary<Type, TypeConverter>
+        {
+            //{ typeof(Uri), new UriTypeConverter() },
+            { typeof(Color), new ColorTypeConverter() },
+            { typeof(Size2D), new Size2DTypeConverter() },
+            { typeof(Position2D), new Position2DTypeConverter() },
+            { typeof(Size), new SizeTypeConverter() },
+            { typeof(Position), new PositionTypeConverter() },
+            { typeof(Rectangle), new RectangleTypeConverter() },
+            { typeof(Rotation), new RotationTypeConverter() },
+            { typeof(Vector2), new Vector2TypeConverter() },
+            { typeof(Vector3), new Vector3TypeConverter() },
+            { typeof(Vector4), new Vector4TypeConverter() },
+            { typeof(RelativeVector2), new RelativeVector2TypeConverter() },
+            { typeof(RelativeVector3), new RelativeVector3TypeConverter() },
+            { typeof(RelativeVector4), new RelativeVector4TypeConverter() },
+        };
     }
 }
index cd95113..48195e6 100755 (executable)
@@ -25,5 +25,11 @@ namespace Tizen.NUI.Binding
 
             throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Extents)}");
         }
+
+        public override string ConvertToString(object value)
+        {
+            Extents extents = (Extents)value;
+            return extents.Start.ToString() + " " + extents.End.ToString() + " " + extents.Top.ToString() + " " + extents.Bottom.ToString();
+        }
     }
 }
index cd3bc41..13fbe10 100755 (executable)
@@ -69,6 +69,12 @@ namespace Tizen.NUI.Binding
 
             throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Position)}");
         }
+
+        public override string ConvertToString(object value)
+        {
+            Position position = (Position)value;
+            return position.X.ToString() + " " + position.Y.ToString() + " " + position.Z.ToString();
+        }
     }
 
     internal class Position2DTypeConverter : TypeConverter
@@ -77,5 +83,11 @@ namespace Tizen.NUI.Binding
         {
             return Position2D.ConvertFromString(value);
         }
+
+        public override string ConvertToString(object value)
+        {
+            Position2D position = (Position2D)value;
+            return  position.X.ToString() + " " + position.Y.ToString();
+        }
     }
 }
index 9bdaef6..00eb488 100755 (executable)
@@ -22,5 +22,11 @@ namespace Tizen.NUI.Binding
 
             throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", value, typeof(Rectangle)));
         }
+
+        public override string ConvertToString(object value)
+        {
+            Rectangle rec = (Rectangle)value;
+            return  rec.X.ToString() + " " + rec.Y.ToString() + " " + rec.Width.ToString() + " " + rec.Height.ToString();
+        }
     }
 }
index c75af23..207da1e 100755 (executable)
@@ -54,5 +54,11 @@ namespace Tizen.NUI.Binding
 
             throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Rotation)}");
         }
+
+        public override string ConvertToString(object value)
+        {
+            Rotation rotation = (Rotation)value;
+            return rotation.ToString();
+        }
     }
 }
index 4d1ecc3..bb449ed 100755 (executable)
@@ -23,6 +23,12 @@ namespace Tizen.NUI.Binding
 
             throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Vector2)}");
         }
+
+        public override string ConvertToString(object value)
+        {
+            Vector2 vector = (Vector2)value;
+            return vector.X.ToString() + " " + vector.Y.ToString();
+        }
     }
 
     internal class Vector3TypeConverter : TypeConverter
@@ -42,6 +48,12 @@ namespace Tizen.NUI.Binding
 
             throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Vector3)}");
         }
+
+        public override string ConvertToString(object value)
+        {
+            Vector3 vector = (Vector3)value;
+            return vector.X.ToString() + " " + vector.Y.ToString() + " " + vector.Z.ToString();
+        }
     }
 
     internal class Vector4TypeConverter : TypeConverter
@@ -62,6 +74,12 @@ namespace Tizen.NUI.Binding
 
             throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Vector4)}");
         }
+
+        public override string ConvertToString(object value)
+        {
+            Vector4 vector = (Vector4)value;
+            return vector.X.ToString() + " " + vector.Y.ToString() + " " + vector.Z.ToString() + " " + vector.W.ToString();
+        }
     }
 
     internal class RelativeVector2TypeConverter : TypeConverter
@@ -80,6 +98,12 @@ namespace Tizen.NUI.Binding
 
             throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(RelativeVector2)}");
         }
+
+        public override string ConvertToString(object value)
+        {
+            RelativeVector2 vector = (RelativeVector2)value;
+            return vector.X.ToString() + " " + vector.Y.ToString();
+        }
     }
 
     internal class RelativeVector3TypeConverter : TypeConverter
@@ -99,6 +123,12 @@ namespace Tizen.NUI.Binding
 
             throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(RelativeVector3)}");
         }
+
+        public override string ConvertToString(object value)
+        {
+            RelativeVector3 vector = (RelativeVector3)value;
+            return vector.X.ToString() + " " + vector.Y.ToString() + " " + vector.Z.ToString();
+        }
     }
 
     internal class RelativeVector4TypeConverter : TypeConverter
@@ -119,5 +149,11 @@ namespace Tizen.NUI.Binding
 
             throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(RelativeVector4)}");
         }
+
+        public override string ConvertToString(object value)
+        {
+            RelativeVector4 vector = (RelativeVector4)value;
+            return vector.X.ToString() + " " + vector.Y.ToString() + " " + vector.Z.ToString() + " " + vector.W.ToString(); ;
+        }
     }
 }
index cbc1eb6..30dad9e 100755 (executable)
@@ -88,6 +88,7 @@ namespace Tizen.NUI.BaseComponents
             if (newValue != null)
             {
                 string url = (string)newValue;
+                view.ClearBackground();
 
                 if (Rectangle.IsNullOrZero(view.backgroundImageBorder))
                 {
index 5e86a2b..495d4ea 100755 (executable)
@@ -17,6 +17,7 @@
 
 using System;
 using System.ComponentModel;
+using System.Reflection;
 using System.Runtime.InteropServices;
 using Tizen.NUI.Binding;
 
@@ -603,5 +604,29 @@ namespace Tizen.NUI.BaseComponents
             transDictionary.TryGetValue(transitionName, out trans);
             return trans;
         }
+
+        /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void ObjectDump()
+        {
+            if ( 0== Children.Count)
+            {
+                Type type = this.GetType();
+                PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
+                foreach(var property in properties)
+                {
+                    if (null != property && property.CanRead)
+                    {
+                        Console.WriteLine($"{type.Name} {property.Name} ({property.PropertyType.Name}): {property.GetValueString(this, property.PropertyType)}");
+                    }
+                }
+                return;
+            }
+
+            foreach (View view in Children)
+            {
+                view.ObjectDump();
+            }
+        }
     }
 }
index 6e14478..b0886b2 100755 (executable)
@@ -999,6 +999,17 @@ namespace Tizen.NUI
             return ret;
         }
 
+        /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void ObjectDump()
+        {
+            Layer rootLayer = GetRootLayer();
+            foreach (View view in rootLayer.Children)
+            {
+                view.ObjectDump();
+            }
+        }
+
         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Window obj)
         {
             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
index 92d786d..8860292 100755 (executable)
@@ -135,5 +135,13 @@ namespace Tizen.NUI.Binding
                     return Color.Black;
             }
         }
+
+        /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public override string ConvertToString(object value)
+        {
+            Color color = (Color)value;
+            return color.R.ToString() + " " + color.G.ToString() + " " + color.B.ToString() + " " + color.A.ToString();
+        }
     }
 }
index 68a2db0..d3a8c0d 100755 (executable)
@@ -32,6 +32,14 @@ namespace Tizen.NUI.Binding
 
             throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Size)}");
         }
+
+        /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public override string ConvertToString(object value)
+        {
+            Size size = (Size)value;
+            return size.Width.ToString() + " " + size.Height.ToString() + " " + size.Depth.ToString();
+        }
     }
 
     /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
@@ -56,5 +64,13 @@ namespace Tizen.NUI.Binding
 
             throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Size2D)}");
         }
+
+        /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public override string ConvertToString(object value)
+        {
+            Size2D size = (Size2D)value;
+            return size.Width.ToString() + " " + size.Height.ToString();
+        }
     }
 }
index 10c6f25..b9d1a3f 100755 (executable)
@@ -42,5 +42,11 @@ namespace Tizen.NUI.Binding
             return ConvertFrom(CultureInfo.InvariantCulture, value);
 #pragma warning restore
         }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public virtual string ConvertToString(object value)
+        {
+            return null;
+        }
     }
 }
\ No newline at end of file