[NUI] add Set/GetAttachedValue method (#2007)
authorYeongJong Lee <cleanlyj@naver.com>
Wed, 16 Sep 2020 07:39:19 +0000 (16:39 +0900)
committerGitHub <noreply@github.com>
Wed, 16 Sep 2020 07:39:19 +0000 (16:39 +0900)
This will fix CA1062(Validate arguments of public methods)

Co-authored-by: dongsug-song <35130733+dongsug-song@users.noreply.github.com>
src/Tizen.NUI/src/public/Layouting/FlexLayout.cs
src/Tizen.NUI/src/public/Layouting/GridLayout.cs
src/Tizen.NUI/src/public/Layouting/LayoutGroup.cs

index d005033..16604a4 100755 (executable)
@@ -105,10 +105,7 @@ namespace Tizen.NUI
         /// <param name="view">The child view.</param>
         /// <returns> The value of alignment self.</returns>
         /// <since_tizen> 8 </since_tizen>
-        public static AlignmentType GetFlexAlignmentSelf(View view)
-        {
-            return (AlignmentType)view.GetValue(FlexAlignmentSelfProperty);
-        }
+        public static AlignmentType GetFlexAlignmentSelf(View view) => GetAttachedValue<AlignmentType>(view, FlexAlignmentSelfProperty);
 
         /// <summary>
         /// Gets the position type of the child view.
@@ -117,10 +114,7 @@ namespace Tizen.NUI
         /// <param name="view">The child view.</param>
         /// <returns> The value of position type</returns>
         /// <since_tizen> 8 </since_tizen>
-        public static PositionType GetFlexPositionType(View view)
-        {
-            return (PositionType)view.GetValue(FlexPositionTypeProperty);
-        }
+        public static PositionType GetFlexPositionType(View view) => GetAttachedValue<PositionType>(view, FlexPositionTypeProperty);
 
         /// <summary>
         /// Gets the aspect ratio of the child view.
@@ -129,10 +123,7 @@ namespace Tizen.NUI
         /// <param name="view">The child view.</param>
         /// <returns> The value of aspect ratio</returns>
         /// <since_tizen> 8 </since_tizen>
-        public static float GetFlexAspectRatio(View view)
-        {
-            return (float)view.GetValue(FlexAspectRatioProperty);
-        }
+        public static float GetFlexAspectRatio(View view) => GetAttachedValue<float>(view, FlexAspectRatioProperty);
 
         /// <summary>
         /// Gets the basis of the child view.
@@ -141,10 +132,7 @@ namespace Tizen.NUI
         /// <param name="view">The child view.</param>
         /// <returns> The value of basis</returns>
         /// <since_tizen> 8 </since_tizen>
-        public static float GetFlexBasis(View view)
-        {
-            return (float)view.GetValue(FlexBasisProperty);
-        }
+        public static float GetFlexBasis(View view) => GetAttachedValue<float>(view, FlexBasisProperty);
 
         /// <summary>
         /// Gets the shrink of the child view.
@@ -153,10 +141,7 @@ namespace Tizen.NUI
         /// <param name="view">The child view.</param>
         /// <returns> The value of shrink</returns>
         /// <since_tizen> 8 </since_tizen>
-        public static float GetFlexShrink(View view)
-        {
-            return (float)view.GetValue(FlexShrinkProperty);
-        }
+        public static float GetFlexShrink(View view) => GetAttachedValue<float>(view, FlexShrinkProperty);
 
         /// <summary>
         /// Gets the grow of the child view.
@@ -165,10 +150,7 @@ namespace Tizen.NUI
         /// <param name="view">The child view.</param>
         /// <returns> The value of grow</returns>
         /// <since_tizen> 8 </since_tizen>
-        public static float GetFlexGrow(View view)
-        {
-            return (float)view.GetValue(FlexGrowProperty);
-        }
+        public static float GetFlexGrow(View view) => GetAttachedValue<float>(view, FlexGrowProperty);
 
         /// <summary>
         /// Sets the alignment self of the child view.<br/>
@@ -179,10 +161,7 @@ namespace Tizen.NUI
         /// <param name="view">The child view.</param>
         /// <param name="value">The value of alignment self.</param>
         /// <since_tizen> 8 </since_tizen>
-        public static void SetFlexAlignmentSelf(View view, AlignmentType value)
-        {
-            SetChildValue(view, FlexAlignmentSelfProperty, value);
-        }
+        public static void SetFlexAlignmentSelf(View view, AlignmentType value) => SetAttachedValue(view, FlexAlignmentSelfProperty, value);
 
         /// <summary>
         /// Sets the position type of the child view.<br/>
@@ -195,10 +174,7 @@ namespace Tizen.NUI
         /// <param name="view">The child view.</param>
         /// <param name="value">The value of position type.</param>
         /// <since_tizen> 8 </since_tizen>
-        public static void SetFlexPositionType(View view, PositionType value)
-        {
-            SetChildValue(view, FlexPositionTypeProperty, value);
-        }
+        public static void SetFlexPositionType(View view, PositionType value) => SetAttachedValue(view, FlexPositionTypeProperty, value);
 
         /// <summary>
         /// Sets the aspect ratio of the child view.
@@ -209,10 +185,7 @@ namespace Tizen.NUI
         /// <param name="view">The child view.</param>
         /// <param name="value">The value of aspect ratio</param>
         /// <since_tizen> 8 </since_tizen>
-        public static void SetFlexAspectRatio(View view, float value)
-        {
-            SetChildValue(view, FlexAspectRatioProperty, value);
-        }
+        public static void SetFlexAspectRatio(View view, float value) => SetAttachedValue(view, FlexAspectRatioProperty, value);
 
         /// <summary>
         /// Sets the flex basis of the child view.
@@ -224,10 +197,7 @@ namespace Tizen.NUI
         /// <param name="view">The child view.</param>
         /// <param name="value">The value of basis</param>
         /// <since_tizen> 8 </since_tizen>
-        public static void SetFlexBasis(View view, float value)
-        {
-            SetChildValue(view, FlexBasisProperty, value);
-        }
+        public static void SetFlexBasis(View view, float value) => SetAttachedValue(view, FlexBasisProperty, value);
 
         /// <summary>
         /// Sets the flex shrink of the child view.
@@ -239,10 +209,7 @@ namespace Tizen.NUI
         /// <param name="view">The child view.</param>
         /// <param name="value">The value of shrink</param>
         /// <since_tizen> 8 </since_tizen>
-        public static void SetFlexShrink(View view, float value)
-        {
-            SetChildValue(view, FlexShrinkProperty, value);
-        }
+        public static void SetFlexShrink(View view, float value) => SetAttachedValue(view, FlexShrinkProperty, value);
 
         /// <summary>
         /// Sets the grow of the child view.
@@ -254,10 +221,7 @@ namespace Tizen.NUI
         /// <param name="view">The child view.</param>
         /// <param name="value">The value of flex</param>
         /// <since_tizen> 8 </since_tizen>
-        public static void SetFlexGrow(View view, float value)
-        {
-            SetChildValue(view, FlexGrowProperty, value);
-        }
+        public static void SetFlexGrow(View view, float value) => SetAttachedValue(view, FlexGrowProperty, value);
 
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         internal delegate MeasuredSize ChildMeasureCallback(global::System.IntPtr child, float width, int measureModeWidth, float height, int measureModeHeight);
@@ -593,7 +557,7 @@ namespace Tizen.NUI
             // Store created node for child
             IntPtr childPtr = Interop.FlexLayout.FlexLayout_AddChildWithMargin(swigCPtr, View.getCPtr(child.Owner), Extents.getCPtr(child.Owner.Margin), measureChildDelegate, LayoutChildren.Count - 1);
             HandleRef childHandleRef = new HandleRef(child.Owner, childPtr);
-            SetChildValue(child.Owner, FlexItemProperty, childHandleRef);
+            SetAttachedValue(child.Owner, FlexItemProperty, childHandleRef);
         }
 
         /// <summary>
index ebeb4a2..77e8d2e 100755 (executable)
@@ -101,145 +101,97 @@ namespace Tizen.NUI
         /// Get the column index.
         /// </summary>
         /// <since_tizen> 8 </since_tizen>
-        public static int GetColumn(View view)
-        {
-            return (int)view.GetValue(ColumnProperty);
-        }
+        public static int GetColumn(View view) => GetAttachedValue<int>(view, ColumnProperty);
 
         /// <summary>
         /// Get the column span.
         /// </summary>
         /// <since_tizen> 8 </since_tizen>
-        public static int GetColumnSpan(View view)
-        {
-            return (int)view.GetValue(ColumnSpanProperty);
-        }
+        public static int GetColumnSpan(View view) => GetAttachedValue<int>(view, ColumnSpanProperty);
 
         /// <summary>
         /// Get the row index.
         /// </summary>
         /// <since_tizen> 8 </since_tizen>
-        public static int GetRow(View view)
-        {
-            return (int)view.GetValue(RowProperty);
-        }
+        public static int GetRow(View view) => GetAttachedValue<int>(view, RowProperty);
 
         /// <summary>
         /// Get the row span.
         /// </summary>
         /// <since_tizen> 8 </since_tizen>
-        public static int GetRowSpan(View view)
-        {
-            return (int)view.GetValue(RowSpanProperty);
-        }
+        public static int GetRowSpan(View view) => GetAttachedValue<int>(view, RowSpanProperty);
 
         /// <summary>
         /// Get the value how child is resized within its horizontal space.
         /// </summary>
         /// <since_tizen> 8 </since_tizen>
-        public static StretchFlags GetHorizontalStretch(View view)
-        {
-            return (StretchFlags)view.GetValue(HorizontalStretchProperty);
-        }
+        public static StretchFlags GetHorizontalStretch(View view) => GetAttachedValue<StretchFlags>(view, HorizontalStretchProperty);
 
         /// <summary>
         /// Get the value how child is resized within its vertical space.
         /// </summary>
         /// <since_tizen> 8 </since_tizen>
-        public static StretchFlags GetVerticalStretch(View view)
-        {
-            return (StretchFlags)view.GetValue(VerticalStretchProperty);
-        }
+        public static StretchFlags GetVerticalStretch(View view) => GetAttachedValue<StretchFlags>(view, VerticalStretchProperty);
 
         /// <summary>
         /// Get the horizontal alignment of this child.
         /// </summary>
         /// <since_tizen> 8 </since_tizen>
-        public static Alignment GetHorizontalAlignment(View view)
-        {
-            return (Alignment)view.GetValue(HorizontalAlignmentProperty);
-        }
+        public static Alignment GetHorizontalAlignment(View view) => GetAttachedValue<Alignment>(view, HorizontalAlignmentProperty);
 
         /// <summary>
         /// Get the vertical alignment of this child.
         /// </summary>
         /// <since_tizen> 8 </since_tizen>
-        public static Alignment GetVerticalAlignment(View view)
-        {
-            return (Alignment)view.GetValue(VerticalAlignmentProperty);
-        }
+        public static Alignment GetVerticalAlignment(View view) => GetAttachedValue<Alignment>(view, VerticalAlignmentProperty);
 
         /// <summary>
         /// Set the column index.
         /// </summary>
         /// <since_tizen> 8 </since_tizen>
-        public static void SetColumn(View view, int value)
-        {
-            SetChildValue(view, ColumnProperty, value);
-        }
+        public static void SetColumn(View view, int value) => SetAttachedValue(view, ColumnProperty, value);
 
         /// <summary>
         /// Set the column span.
         /// </summary>
         /// <since_tizen> 8 </since_tizen>
-        public static void SetColumnSpan(View view, int value)
-        {
-            SetChildValue(view, ColumnSpanProperty, value);
-        }
+        public static void SetColumnSpan(View view, int value) => SetAttachedValue(view, ColumnSpanProperty, value);
 
         /// <summary>
         /// Set the row index.
         /// </summary>
         /// <since_tizen> 8 </since_tizen>
-        public static void SetRow(View view, int value)
-        {
-            SetChildValue(view, RowProperty, value);
-        }
+        public static void SetRow(View view, int value) => SetAttachedValue(view, RowProperty, value);
 
         /// <summary>
         /// Set the row span.
         /// </summary>
         /// <since_tizen> 8 </since_tizen>
-        public static void SetRowSpan(View view, int value)
-        {
-            SetChildValue(view, RowSpanProperty, value);
-        }
+        public static void SetRowSpan(View view, int value) => SetAttachedValue(view, RowSpanProperty, value);
 
         /// <summary>
         /// Set the value how child is resized within its horizontal space. <see cref="StretchFlags.Fill"/> by default.
         /// </summary>
         /// <since_tizen> 8 </since_tizen>
-        public static void SetHorizontalStretch(View view, StretchFlags value)
-        {
-            SetChildValue(view, HorizontalStretchProperty, value);
-        }
+        public static void SetHorizontalStretch(View view, StretchFlags value) => SetAttachedValue(view, HorizontalStretchProperty, value);
 
         /// <summary>
         /// Set the value how child is resized within its vertical space. <see cref="StretchFlags.Fill"/> by default.
         /// </summary>
         /// <since_tizen> 8 </since_tizen>
-        public static void SetVerticalStretch(View view, StretchFlags value)
-        {
-            SetChildValue(view, VerticalStretchProperty, value);
-        }
+        public static void SetVerticalStretch(View view, StretchFlags value) => SetAttachedValue(view, VerticalStretchProperty, value);
 
         /// <summary>
         /// Set the horizontal alignment of this child inside the cells.
         /// </summary>
         /// <since_tizen> 8 </since_tizen>
-        public static void SetHorizontalAlignment(View view, Alignment value)
-        {
-            SetChildValue(view, HorizontalAlignmentProperty, value);
-        }
+        public static void SetHorizontalAlignment(View view, Alignment value) => SetAttachedValue(view, HorizontalAlignmentProperty, value);
 
         /// <summary>
         /// Set the vertical alignment of this child inside the cells.
         /// </summary>
         /// <since_tizen> 8 </since_tizen>
-        public static void SetVerticalAlignment(View view, Alignment value)
-        {
-            SetChildValue(view, VerticalAlignmentProperty, value);
-        }
+        public static void SetVerticalAlignment(View view, Alignment value) => SetAttachedValue(view, VerticalAlignmentProperty, value);
 
         /// <summary>
         /// The distance between columns.
index 901b1eb..71df49e 100755 (executable)
@@ -553,8 +553,34 @@ namespace Tizen.NUI
 
         }
 
-        internal static void SetChildValue(Binding.BindableObject bindable, Binding.BindableProperty property, object value)
+        /// <summary>
+        /// Gets the value that is contained in the attached BindableProperty.
+        /// </summary>
+        /// <typeparam name="T">The return type of property</typeparam>
+        /// <param name="bindable">The bindable object.</param>
+        /// <param name="property">The BindableProperty for which to get the value.</param>
+        /// <returns>The value that is contained in the attached BindableProperty.</returns>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static T GetAttachedValue<T>(Binding.BindableObject bindable, Binding.BindableProperty property)
         {
+            if (bindable == null)
+                throw new ArgumentNullException(nameof(bindable));
+
+            return (T)bindable.GetValue(property);
+        }
+
+        /// <summary>
+        /// Sets the value of the attached property.
+        /// </summary>
+        /// <param name="bindable">The bindable object.</param>
+        /// <param name="property">The BindableProperty on which to assign a value.</param>
+        /// <param name="value">The value to set.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static void SetAttachedValue(Binding.BindableObject bindable, Binding.BindableProperty property, object value)
+        {
+            if (bindable == null)
+                throw new ArgumentNullException(nameof(bindable));
+
             bindable.SetValueCore(property, value, SetValueFlags.None, SetValuePrivateFlags.ManuallySet, false);
         }
         internal static void OnChildPropertyChanged(Binding.BindableObject bindable, object oldValue, object newValue)