[NUI] Fix CA1819 : Properties should not return arrays (#2409)
authorAdunFang <30402408+AdunFang@users.noreply.github.com>
Tue, 26 Jan 2021 03:33:52 +0000 (11:33 +0800)
committerJiyun Yang <ji.yang@samsung.com>
Tue, 26 Jan 2021 08:27:40 +0000 (17:27 +0900)
* [NUI] Fix CA1819

* [NUI] Fix CA1819

* [NUI] Rename private member

* [NUI] Modify code by HQ's comments

* [NUI] Change the category of SuppressMessage

Co-authored-by: Fang Xiaohui <xiaohui fang>
Co-authored-by: Jiyun Yang <ji.yang@samsung.com>
src/Tizen.NUI/src/internal/FrameBroker/DefaultFrameBroker.cs
src/Tizen.NUI/src/public/Animation.cs
src/Tizen.NUI/src/public/BaseComponents/View.cs
src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs
src/Tizen.NUI/src/public/XamlBinding/Transition.cs

index 41a0e1d..9c682be 100755 (executable)
@@ -109,17 +109,13 @@ namespace Tizen.NUI
                 providerImage.Show();
                 int propertyCount = transition.AnimationDataList.Count;
                 animation = new Animation(transition.DurationMilliSeconds+80);
-                animation.Properties = new string[propertyCount];
-                animation.DestValue = new string[propertyCount];
-                animation.StartTime = new int[propertyCount];
-                animation.EndTime = new int[propertyCount];
 
                 for (int i = 0; i < propertyCount; i++)
                 {
-                    animation.Properties[i] = transition.AnimationDataList[i].Property;
-                    animation.DestValue[i] = transition.AnimationDataList[i].DestinationValue;
-                    animation.StartTime[i] = 80+transition.AnimationDataList[i].StartTime;
-                    animation.EndTime[i] = 80+transition.AnimationDataList[i].EndTime;
+                    animation.PropertyList.Add(transition.AnimationDataList[i].Property);
+                    animation.DestValueList.Add(transition.AnimationDataList[i].DestinationValue);
+                    animation.StartTimeList.Add(80 +transition.AnimationDataList[i].StartTime);
+                    animation.EndTimeList.Add(80 +transition.AnimationDataList[i].EndTime);
                 }
                 animation.PlayAnimateTo(providerImage);
                 animation.Finished += Ani_Finished;
index 914d6a5..0c27f70 100755 (executable)
@@ -31,6 +31,7 @@ namespace Tizen.NUI
     using Tizen.NUI.Binding;
     using System.Globalization;
     using Tizen.NUI.Xaml.Internals;
+    using System.Diagnostics.CodeAnalysis;
 
     /// <summary>
     /// Animation can be used to animate the properties of any number of objects, typically view.<br />
@@ -55,6 +56,11 @@ namespace Tizen.NUI
         private int[] _startTime = null;
         private int[] _endTime = null;
 
+        private List<string> propertyList = null;
+        private List<string> destValueList = null;
+        private List<int> startTimeList = null;
+        private List<int> endTimeList = null;
+
         /// <summary>
         /// Creates an initialized animation.<br />
         /// The animation will not loop.<br />
@@ -436,6 +442,8 @@ namespace Tizen.NUI
         /// <summary>
         /// Gets or sets the properties of the animation.
         /// </summary>
+        //ToDo : will raise deprecated-ACR, [Obsolete("Deprecated in API9, Will be removed in API11, Please use PropertyList instead")]
+        [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "This API will be deprecated, so suppressing the warning for now")]
         public string[] Properties
         {
             get
@@ -451,6 +459,8 @@ namespace Tizen.NUI
         /// <summary>
         /// Gets or sets the destination value for each property of the animation.
         /// </summary>
+        //ToDo : will raise deprecated-ACR, [Obsolete("Deprecated in API9, Will be removed in API11, Please use DestValueList instead")]
+        [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "This API will be deprecated, so suppressing the warning for now")]
         public string[] DestValue
         {
             get
@@ -466,6 +476,8 @@ namespace Tizen.NUI
         /// <summary>
         /// Gets or sets the start time for each property of the animation.
         /// </summary>
+        //ToDo : will raise deprecated-ACR, [Obsolete("Deprecated in API9, Will be removed in API11, Please use StartTimeList instead")]
+        [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "This API will be deprecated, so suppressing the warning for now")]
         public int[] StartTime
         {
             get
@@ -481,6 +493,8 @@ namespace Tizen.NUI
         /// <summary>
         /// Gets or sets the end time for each property of the animation.
         /// </summary>
+        //ToDo : will raise deprecated-ACR, [Obsolete("Deprecated in API9, Will be removed in API11, Please use EndTimeList instead")]
+        [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "This API will be deprecated, so suppressing the warning for now")]
         public int[] EndTime
         {
             get
@@ -493,6 +507,74 @@ namespace Tizen.NUI
             }
         }
 
+        /// <summary>
+        /// Get the list of the properties of the animation.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public IList<string> PropertyList
+        {
+            get
+            {
+                if (null == propertyList)
+                {
+                    propertyList = new List<string>();
+                }
+
+                return propertyList;
+            }
+        }
+
+        /// <summary>
+        /// Get the list of the destination value for each property of the animation.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public IList<string> DestValueList
+        {
+            get
+            {
+                if (null == destValueList)
+                {
+                    destValueList = new List<string>();
+                }
+
+                return destValueList;
+            }
+        }
+
+        /// <summary>
+        /// Get the list of the start time for each property of the animation.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public IList<int> StartTimeList
+        {
+            get
+            {
+                if (null == startTimeList)
+                {
+                    startTimeList = new List<int>();
+                }
+
+                return startTimeList;
+            }
+        }
+
+        /// <summary>
+        /// Get the list of end time for each property of the animation.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public IList<int> EndTimeList
+        {
+            get
+            {
+                if (null == endTimeList)
+                {
+                    endTimeList = new List<int>();
+                }
+
+                return endTimeList;
+            }
+        }
+
         private bool DisableAnimation
         {
             get
@@ -673,26 +755,57 @@ namespace Tizen.NUI
             }
 
             Clear();
-            if (_properties.Length == _destValue.Length && _startTime.Length == _endTime.Length && _properties.Length == _startTime.Length)
+
+            if (null != propertyList && null != destValueList && null != startTimeList && null != endTimeList)
             {
-                int length = _properties.Length;
-                for (int index = 0; index < length; index++)
+                if (propertyList.Count == destValueList.Count
+                    &&
+                    startTimeList.Count == endTimeList.Count
+                    &&
+                    propertyList.Count == startTimeList.Count)
                 {
-                    //object destinationValue = _destValue[index];
-                    var elementType = target.GetType();
-                    PropertyInfo propertyInfo = elementType.GetProperties().FirstOrDefault(fi => fi.Name == _properties[index]);
-                    //var propertyInfo = elementType.GetRuntimeProperties().FirstOrDefault(p => p.Name == localName);
-                    if (propertyInfo != null)
+                    int count = propertyList.Count;
+                    for (int index = 0; index < count; index++)
                     {
-                        object destinationValue = ConvertTo(_destValue[index], propertyInfo.PropertyType);
+                        var elementType = target.GetType();
+                        PropertyInfo propertyInfo = elementType.GetProperties().FirstOrDefault(fi => fi.Name == propertyList[index]);
 
-                        if (destinationValue != null)
+                        if (propertyInfo != null)
                         {
-                            AnimateTo(target, _properties[index], destinationValue, _startTime[index], _endTime[index]);
+                            object destinationValue = ConvertTo(destValueList[index], propertyInfo.PropertyType);
+
+                            if (destinationValue != null)
+                            {
+                                AnimateTo(target, propertyList[index], destinationValue, startTimeList[index], endTimeList[index]);
+                            }
+                        }
+                    }
+                    Play();
+                }
+            }
+            else
+            {
+                if (_properties.Length == _destValue.Length && _startTime.Length == _endTime.Length && _properties.Length == _startTime.Length)
+                {
+                    int length = _properties.Length;
+                    for (int index = 0; index < length; index++)
+                    {
+                        //object destinationValue = _destValue[index];
+                        var elementType = target.GetType();
+                        PropertyInfo propertyInfo = elementType.GetProperties().FirstOrDefault(fi => fi.Name == _properties[index]);
+                        //var propertyInfo = elementType.GetRuntimeProperties().FirstOrDefault(p => p.Name == localName);
+                        if (propertyInfo != null)
+                        {
+                            object destinationValue = ConvertTo(_destValue[index], propertyInfo.PropertyType);
+
+                            if (destinationValue != null)
+                            {
+                                AnimateTo(target, _properties[index], destinationValue, _startTime[index], _endTime[index]);
+                            }
                         }
                     }
+                    Play();
                 }
-                Play();
             }
         }
 
index 151abfa..8ba60fb 100755 (executable)
@@ -41,7 +41,6 @@ namespace Tizen.NUI.BaseComponents
         private float weight = 0.0f; // Weighting of child View in a Layout
         private bool backgroundImageSynchronosLoading = false;
         private Dictionary<string, Transition> transDictionary = new Dictionary<string, Transition>();
-        private string[] transitionNames;
         private bool controlStatePropagation = false;
         private ViewStyle viewStyle;
         private bool themeChangeSensitive = false;
@@ -2323,21 +2322,6 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
-        /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public string[] TransitionNames
-        {
-            get
-            {
-                return transitionNames;
-            }
-            set
-            {
-                transitionNames = value;
-                LoadTransitions();
-            }
-        }
-
         /// <summary>
         /// Enable/Disable ControlState propagation for children.
         /// It is false by default.
@@ -2511,5 +2495,14 @@ namespace Tizen.NUI.BaseComponents
                 }
             }
         }
+
+        /// <summary>
+        /// Used to restore the transition.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public IList<Transition> TransitionList
+        {
+            get;
+        } = new List<Transition>();
     }
 }
index 1a7f769..74646f6 100755 (executable)
@@ -1295,28 +1295,6 @@ namespace Tizen.NUI.BaseComponents
             return view;
         }
 
-        private void LoadTransitions()
-        {
-            foreach (string str in transitionNames)
-            {
-                string resourceName = str + ".xaml";
-                Transition trans = null;
-
-                string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
-
-                string likelyResourcePath = resource + "animation/" + resourceName;
-
-                if (File.Exists(likelyResourcePath))
-                {
-                    trans = Xaml.Extensions.LoadObject<Transition>(likelyResourcePath);
-                }
-                if (trans != null)
-                {
-                    transDictionary.Add(trans.Name, trans);
-                }
-            }
-        }
-
         private void OnScaleChanged(float x, float y, float z)
         {
             Scale = new Vector3(x, y, z);
index b4e7d72..8f0b5c5 100755 (executable)
@@ -1,3 +1,4 @@
+using System.Collections;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.IO;
@@ -11,13 +12,11 @@ using static Tizen.NUI.Animation;
 namespace Tizen.NUI
 {
     /// <since_tizen> 5 </since_tizen>
-    /// 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 class AnimationBehavior
     {
         private string _key = null;
         /// <since_tizen> 5 </since_tizen>
-        /// 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 string Key
         {
@@ -34,7 +33,6 @@ namespace Tizen.NUI
         private string _property = null;
 
         /// <since_tizen> 5 </since_tizen>
-        /// 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 string Property
         {
@@ -51,7 +49,6 @@ namespace Tizen.NUI
         private string _destValue = null;
 
         /// <since_tizen> 5 </since_tizen>
-        /// 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 string DestValue
         {
@@ -68,7 +65,6 @@ namespace Tizen.NUI
         private int _startTime = -1;
 
         /// <since_tizen> 5 </since_tizen>
-        /// 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 int StartTime
         {
@@ -85,7 +81,6 @@ namespace Tizen.NUI
         private int _endTime = -1;
 
         /// <since_tizen> 5 </since_tizen>
-        /// 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 int EndTime
         {
@@ -100,15 +95,49 @@ namespace Tizen.NUI
         }
     }
 
+
+    /// <summary>
+    /// It is the container to contain the behaviors of Transition.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class BehaviorContainer : List<AnimationBehavior>
+    {
+        private Dictionary<string, AnimationBehavior> behaviors = new Dictionary<string, AnimationBehavior>();
+
+        /// <summary>
+        /// The method for user to add behavior.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void Add(object obj)
+        {
+            var behavior = obj as AnimationBehavior;
+
+            if (null != behavior)
+            {
+                behaviors.Add(behavior.Key, behavior);
+            }
+        }
+
+        /// <summary>
+        /// The method for user to get the behavior by the key.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public AnimationBehavior GetAnimationBehavior(string key)
+        {
+            AnimationBehavior behavior = null;
+            behaviors.TryGetValue(key, out behavior);
+
+            return behavior;
+        }
+    }
+
     /// <since_tizen> 5 </since_tizen>
-    /// 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 class Transition : Animation
     {
         private string name;
 
         /// <since_tizen> 5 </since_tizen>
-        /// 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 string Name
         {
@@ -122,32 +151,11 @@ namespace Tizen.NUI
             }
         }
 
-        private Dictionary<string, AnimationBehavior> behaviors = new Dictionary<string, AnimationBehavior>();
-
-        /// <summary>
-        /// Hidden-API (Inhouse-API).
-        /// Convert previous "public AnimationBehavior[] Behaviors" property to method.
-        /// </summary>
-        /// <param name="Behaviors">Array of AnimationBehavior type</param>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public void SetBehaviors(AnimationBehavior[] Behaviors)
-        {
-            if (null != Behaviors)
-            {
-                foreach (AnimationBehavior behavior in Behaviors)
-                {
-                    behaviors.Add(behavior.Key, behavior);
-                }
-            }
-        }
-
         /// <since_tizen> 5 </since_tizen>
-        /// 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 void AnimateTo(View instance, string behaviorKey)
         {
-            AnimationBehavior behavior = null;
-            behaviors.TryGetValue(behaviorKey, out behavior);
+            AnimationBehavior behavior = Behaviors?.GetAnimationBehavior(behaviorKey);
 
             if (null != instance && null != behavior)
             {
@@ -178,12 +186,10 @@ namespace Tizen.NUI
         }
 
         /// <since_tizen> 5 </since_tizen>
-        /// 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 void AnimateBy(View instance, string behaviorKey)
         {
-            AnimationBehavior behavior = null;
-            behaviors.TryGetValue(behaviorKey, out behavior);
+            AnimationBehavior behavior = Behaviors?.GetAnimationBehavior(behaviorKey);
 
             if (null != instance && null != behavior)
             {
@@ -212,5 +218,12 @@ namespace Tizen.NUI
                 throw new XamlParseException(string.Format("Behaviors don't have key {0}", behaviorKey), new XmlLineInfo());
             }
         }
+
+        /// <since_tizen> 5 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public BehaviorContainer Behaviors
+        {
+            get;
+        } = new BehaviorContainer();
     }
 }