[NUI]Fix build warning[CA1001]
authorhuiyu.eun <huiyu.eun@samsung.com>
Tue, 22 Dec 2020 03:46:26 +0000 (12:46 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 22 Dec 2020 08:57:34 +0000 (17:57 +0900)
https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1001
CA1001: Types that own disposable fields should be disposable

Signed-off-by: huiyu.eun <huiyu.eun@samsung.com>
16 files changed:
src/Tizen.NUI.Components/Controls/Extension/SlidingSwitchExtension.cs
src/Tizen.NUI.Components/Style/ButtonStyle.cs
src/Tizen.NUI.Components/Style/ControlStyle.cs
src/Tizen.NUI.Components/Style/SliderStyle.cs
src/Tizen.NUI.Wearable/src/public/WearableStyle/CircularProgressStyle.cs
src/Tizen.NUI/src/internal/DisposeQueue.cs
src/Tizen.NUI/src/public/Accessibility/Accessibility.cs
src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs
src/Tizen.NUI/src/public/KeyValue.cs
src/Tizen.NUI/src/public/Layouting/FlexLayout.cs
src/Tizen.NUI/src/public/Layouting/LayoutItem.cs
src/Tizen.NUI/src/public/Layouting/LayoutTransition.cs
src/Tizen.NUI/src/public/TransitionAnimations/TransitionAnimations.cs
src/Tizen.NUI/src/public/ViewProperty/BackgroundExtraData.cs
src/Tizen.NUI/src/public/ViewProperty/TextShadow.cs
src/Tizen.NUI/src/public/VisualMaps.cs

index 1086ceb453278b3e689e5a5ea79d75e864970c9f..b52ba0e678e78530c8e14a5ccf84f479b9dea9b4 100755 (executable)
@@ -27,8 +27,9 @@ namespace Tizen.NUI.Components.Extension
     /// </remark>
     /// </summary>
     [EditorBrowsable(EditorBrowsableState.Never)]
-    internal class SlidingSwitchExtension : SwitchExtension
+    internal class SlidingSwitchExtension : SwitchExtension, IDisposable
     {
+        private bool disposed = false;
         private Animation slidingAnimation;
 
         public SlidingSwitchExtension() : base()
@@ -80,5 +81,28 @@ namespace Tizen.NUI.Components.Extension
                 slidingAnimation = null;
             }
         }
+
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected virtual void Dispose(bool disposing)
+        {
+            if (disposed)
+            {
+                return;
+            }
+
+            if (disposing)
+            {
+                slidingAnimation?.Dispose();
+            }
+            disposed = true;
+        }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void Dispose()
+        {
+            Dispose(true);
+            global::System.GC.SuppressFinalize(this);
+        }
     }
 }
index 321e3b8ece1a4903b62e862c602f7ea9be5278a2..0b132a16809b1266a284ee974d9e34bcedfa3be1 100755 (executable)
@@ -234,22 +234,17 @@ namespace Tizen.NUI.Components
         /// <summary>
         /// Dispose ButtonStyle and all children on it.
         /// </summary>
-        /// <param name="type">Dispose type.</param>
+        /// <param name="disposing">true in order to free managed objects</param>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        protected override void Dispose(DisposeTypes type)
+        protected override void Dispose(bool disposing)
         {
-            if (Disposed)
-            {
-                return;
-            }
-
-            if (type == DisposeTypes.Explicit)
+            if (disposing)
             {
                 iconPadding?.Dispose();
                 textPadding?.Dispose();
             }
 
-            base.Dispose(type);
+            base.Dispose(disposing);
         }
     }
 }
index 63c170b404ac71ca30cec7a17e29cd076af27c25..75937174a9966bede1e0411ac3ee380528ac1254 100755 (executable)
@@ -25,10 +25,8 @@ namespace Tizen.NUI.Components
     /// <since_tizen> 6 </since_tizen>
     /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
     [EditorBrowsable(EditorBrowsableState.Never)]
-    public class ControlStyle : ViewStyle, global::System.IDisposable
+    public class ControlStyle : ViewStyle
     {
-        private bool isDisposeQueued = false;
-
         static ControlStyle()
         {
             ThemeManager.AddPackageTheme(new DefaultThemeCreator());
@@ -56,69 +54,6 @@ namespace Tizen.NUI.Components
         {
         }
 
-        /// <summary>
-        /// Dispose.
-        /// </summary>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        ~ControlStyle()
-        {
-            if (!isDisposeQueued)
-            {
-                isDisposeQueued = true;
-                DisposeQueue.Instance.Add(this);
-            }
-        }
-
-        /// <summary>
-        /// A Flag to check if it is already disposed.
-        /// </summary>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        protected bool Disposed { get; set; }
-
-        /// <summary>
-        /// Dispose.
-        /// </summary>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public void Dispose()
-        {
-            //Throw excpetion if Dispose() is called in separate thread.
-            if (!Window.IsInstalled())
-            {
-                throw new global::System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
-            }
-
-            if (isDisposeQueued)
-            {
-                Dispose(DisposeTypes.Implicit);
-            }
-            else
-            {
-                Dispose(DisposeTypes.Explicit);
-                global::System.GC.SuppressFinalize(this);
-            }
-        }
-
-        /// <summary>
-        /// Dispose.
-        /// </summary>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        protected virtual void Dispose(DisposeTypes type)
-        {
-            if (Disposed)
-            {
-                return;
-            }
-
-            if (type == DisposeTypes.Explicit)
-            {
-                //Called by User
-                //Release your own managed resources here.
-                //You should release all of your own disposable objects here.
-            }
-
-            Disposed = true;
-        }
-
         private void SubStyleCalledEvent(object sender, global::System.EventArgs e)
         {
             OnPropertyChanged();
index 2847861071f4336c4ec42c602951cb53e54c4519..a7b7bd810dc4751b103dea84842174313bdb33c6 100755 (executable)
@@ -214,21 +214,16 @@ namespace Tizen.NUI.Components
         /// <summary>
         /// Dispose SliderStyle and all children on it.
         /// </summary>
-        /// <param name="type">Dispose type.</param>
+        /// <param name="disposing">true in order to free managed objects</param>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        protected override void Dispose(DisposeTypes type)
+        protected override void Dispose(bool disposing)
         {
-            if (Disposed)
-            {
-                return;
-            }
-
-            if (type == DisposeTypes.Explicit)
+            if (disposing)
             {
                 trackPadding?.Dispose();
             }
 
-            base.Dispose(type);
+            base.Dispose(disposing);
         }
     }
 }
index 684684f90cc15fb9612b1e9fd4c35ec0eaedd2d0..4bfa081a130ca6570c331a1d1d7fdf47e2b60ea2 100755 (executable)
@@ -247,22 +247,17 @@ namespace Tizen.NUI.Wearable
         /// <summary>
         /// Dispose CircularProgressStyle and all children on it.
         /// </summary>
-        /// <param name="type">Dispose type.</param>
+        /// <param name="disposing">true in order to free managed objects</param>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        protected override void Dispose(DisposeTypes type)
+        protected override void Dispose(bool disposing)
         {
-            if (Disposed)
-            {
-                return;
-            }
-
-            if (type == DisposeTypes.Explicit)
+            if (disposing)
             {
                 trackColor?.Dispose();
                 progressColor?.Dispose();
             }
 
-            base.Dispose(type);
+            base.Dispose(disposing);
         }
 
         private void Initialize()
index 21fd422e3433bace40b3bf790d80dbd0ad5521b4..6fecc1d0e8de2145e7c76d2109713548d7252ef2 100755 (executable)
@@ -9,9 +9,11 @@
 
 using System;
 using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
 
 namespace Tizen.NUI
 {
+    [SuppressMessage("Microsoft.Design", "CA1001:Types that own disposable fields should be disposable", Justification = "This is a singleton class and is not disposed")]
     internal class DisposeQueue
     {
         private static readonly DisposeQueue _disposableQueue = new DisposeQueue();
index 7631c62cae5fedb3c678cd9e2f77c2d636c2572f..99a9d22fca9c1d50c2cd7c38e334f2fd841acf7e 100755 (executable)
@@ -31,6 +31,7 @@ namespace Tizen.NUI.Accessibility
     /// </summary>
     // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
     [SuppressMessage("Microsoft.Design", "CA1724: Type names should not match namespaces")]
+    [SuppressMessage("Microsoft.Design", "CA1001:Types that own disposable fields should be disposable", Justification = "This is a singleton class and is not disposed")]
     [EditorBrowsable(EditorBrowsableState.Never)]
     public class Accessibility
     {
index 782e050c01637f3f5562763ba6cb52b2ee2ff920..b1cd97019728928be2c817b4b669b0e6b3b0b3df 100755 (executable)
@@ -26,8 +26,9 @@ namespace Tizen.NUI.BaseComponents
     /// </summary>
     /// 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 partial class ViewStyle : BindableObject
+    public partial class ViewStyle : BindableObject, IDisposable
     {
+        private bool disposed = false;
         private string styleName;
         private View.States? state;
         private View.States? subState;
@@ -768,5 +769,45 @@ namespace Tizen.NUI.BaseComponents
         {
             Margin = new Extents(start, end, top, bottom);
         }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected virtual void Dispose(bool disposing)
+        {
+            if (disposed)
+            {
+                return;
+            }
+
+            if (disposing)
+            {
+                // Dispose managed state (managed objects).
+                cellIndex?.Dispose();
+                downFocusableView?.Dispose();
+                flexMargin?.Dispose();
+                leftFocusableView?.Dispose();
+                margin?.Dispose();
+                maximumSize?.Dispose();
+                minimumSize?.Dispose();
+                orientation?.Dispose();
+                padding?.Dispose();
+                parentOrigin?.Dispose();
+                pivotPoint?.Dispose();
+                position?.Dispose();
+                rightFocusableView?.Dispose();
+                scale?.Dispose();
+                size?.Dispose();
+                sizeModeFactor?.Dispose();
+                upFocusableView?.Dispose();
+            }
+
+            disposed = true;
+        }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void Dispose()
+        {
+            Dispose(true);
+            global::System.GC.SuppressFinalize(this);
+        }
     }
 }
index ade27e28d45349a616317a87bbb09c3b7c0e3f65..77497d27d2d42096f4dd6c4c1a236ac022f80f6d 100755 (executable)
@@ -16,6 +16,7 @@
  */
 
 using System;
+using System.ComponentModel;
 using Tizen.NUI.Binding;
 
 namespace Tizen.NUI
@@ -23,8 +24,9 @@ namespace Tizen.NUI
     /// <summary>
     /// KeyValue class.
     /// </summary>
-    public class KeyValue
+    public class KeyValue : IDisposable
     {
+        private bool disposed = false;
         /// <summary>
         /// Int key.
         /// </summary>
@@ -548,5 +550,28 @@ namespace Tizen.NUI
                 KeyString = Key;
             }
         }
+
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected virtual void Dispose(bool disposing)
+        {
+            if (disposed)
+            {
+                return;
+            }
+
+            if (disposing)
+            {
+                TrueValue?.Dispose();
+            }
+            disposed = true;
+        }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void Dispose()
+        {
+            Dispose(true);
+            global::System.GC.SuppressFinalize(this);
+        }
     }
 }
index dc5b3c78270db40855c4bac54bdef14e5f135cb5..a11d719f591a9a160504088d05e932019961aa85 100755 (executable)
@@ -29,7 +29,7 @@ namespace Tizen.NUI
     /// For more information about the flex layout API and how to use it please refer to https://yogalayout.com/docs/
     /// We implement the subset of the API in the class below.
     /// </summary>
-    public class FlexLayout : LayoutGroup, global::System.IDisposable
+    public class FlexLayout : LayoutGroup
     {
         /// <summary>
         /// FlexItemProperty
@@ -285,7 +285,7 @@ namespace Tizen.NUI
 
         /// <inheritdoc/>
         /// <since_tizen> 6 </since_tizen>
-        public void Dispose()
+        public new void Dispose()
         {
             Dispose(true);
             System.GC.SuppressFinalize(this);
@@ -302,7 +302,7 @@ namespace Tizen.NUI
         /// <param name="disposing">true in order to free managed objects</param>
         // Protected implementation of Dispose pattern.
         [EditorBrowsable(EditorBrowsableState.Never)]
-        protected virtual void Dispose(bool disposing)
+        protected override void Dispose(bool disposing)
         {
             if (disposedThis)
             {
@@ -341,8 +341,8 @@ namespace Tizen.NUI
 
             // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
             // TODO: set large fields to null.
-
             disposedThis = true;
+            base.Dispose(disposing);
         }
 
         /// <inheritdoc/>
index 97a63c1d1ba0a674204b2498a7076915047ea778..4a83d703119f9ed0d97d260147acc298934c744b 100755 (executable)
@@ -37,8 +37,9 @@ namespace Tizen.NUI
     /// [Draft] Base class for layouts. It is used to layout a View
     /// It can be laid out by a LayoutGroup.
     /// </summary>
-    public class LayoutItem
+    public class LayoutItem : IDisposable
     {
+        private bool disposed = false;
         static bool LayoutDebugFrameData = false; // Debug flag
         private MeasureSpecification OldWidthMeasureSpec; // Store measure specification to compare against later
         private MeasureSpecification OldHeightMeasureSpec; // Store measure specification to compare against later
@@ -624,5 +625,29 @@ namespace Tizen.NUI
 
             return changed;
         }
+
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected virtual void Dispose(bool disposing)
+        {
+            if(disposed)
+            {
+                return;
+            }
+
+            if (disposing)
+            {
+                _margin?.Dispose();
+                _padding?.Dispose();
+            }
+            disposed = true;
+        }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void Dispose()
+        {
+            Dispose(true);
+            global::System.GC.SuppressFinalize(this);
+        }
     }
 }
index 3611f15b6993b9011f0ea49a0c26048f82ebd951..e43d141cab4ef0e1557211973bb55e7724d99e59 100755 (executable)
@@ -17,6 +17,7 @@
 
 using System.Collections.Generic;
 using System;
+using System.ComponentModel;
 
 namespace Tizen.NUI
 {
@@ -100,8 +101,9 @@ namespace Tizen.NUI
     /// Parts of the transition that can be configured to provide a custom effect.
     /// </summary>
     /// <since_tizen> 6 </since_tizen>
-    public class TransitionComponents
+    public class TransitionComponents : IDisposable
     {
+        private bool disposed = false;
         /// <summary>
         /// TransitionComponents default constructor.
         /// </summary>
@@ -143,6 +145,28 @@ namespace Tizen.NUI
         /// </summary>
         /// <since_tizen> 6 </since_tizen>
         public AlphaFunction AlphaFunction;
+
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected virtual void Dispose(bool disposing)
+        {
+            if (disposed)
+            {
+                return;
+            }
+            if (disposing)
+            {
+                AlphaFunction?.Dispose();
+            }
+            disposed = true;
+        }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void Dispose()
+        {
+            Dispose(true);
+            global::System.GC.SuppressFinalize(this);
+        }
     }
 
     /// <summary>
index f2799d590b89d5137040ce7df19460658c41f4bc..dbd016cb353d764240ac537a22b14b6b4d4ec8ae 100755 (executable)
@@ -42,8 +42,9 @@ namespace Tizen.NUI
     /// Transition animation effect
     /// </summary>
     [EditorBrowsable(EditorBrowsableState.Never)]
-    public class TransitionAnimation
+    public class TransitionAnimation : IDisposable
     {
+        private bool disposed = false;
         private ImageViewStyle defaultImageStyle;
         private List<TransitionAnimationData> animationDataList;
         
@@ -136,6 +137,28 @@ namespace Tizen.NUI
                 defaultImageStyle = value;
             }
         }
+
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected virtual void Dispose(bool disposing)
+        {
+            if (disposed)
+            {
+                return;
+            }
+            if (disposing)
+            {
+                defaultImageStyle?.Dispose();
+            }
+            disposed = true;
+        }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void Dispose()
+        {
+            Dispose(true);
+            global::System.GC.SuppressFinalize(this);
+        }
     }
 
     /// <summary>
index 8d950884ca529f4d10c1b43f11102671392b8989..ba4efd820970cfb81130466bc47777c196dcd2ae 100755 (executable)
  * limitations under the License.
  *
  */
+using System;
+using System.ComponentModel;
 
 namespace Tizen.NUI
 {
     /// <summary>
     /// The class storing Background extra properties such as CornerRadius, ImageBorder.
     /// </summary>
-    internal class BackgroundExtraData
+    internal class BackgroundExtraData : IDisposable
     {
+        private bool disposed = false;
         internal BackgroundExtraData()
         {
         }
@@ -53,6 +56,28 @@ namespace Tizen.NUI
         {
             return CornerRadius == 0 && Rectangle.IsNullOrZero(BackgroundImageBorder);
         }
+
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected virtual void Dispose(bool disposing)
+        {
+            if (disposed)
+            {
+                return;
+            }
+            if (disposing)
+            {
+                backgroundImageBorder?.Dispose();
+            }
+            disposed = true;
+        }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void Dispose()
+        {
+            Dispose(true);
+            global::System.GC.SuppressFinalize(this);
+        }
     }
 }
 
index af116f8d9b05332912908a0c64d12ac4ac623387..2a31ec3b61b51e1f643b4f32383b147289b8c824 100755 (executable)
@@ -24,8 +24,9 @@ namespace Tizen.NUI
     /// The Text Shadow for TextLabel.
     /// </summary>
     [EditorBrowsable(EditorBrowsableState.Never)]
-    public class TextShadow : ICloneable
+    public class TextShadow : ICloneable, IDisposable
     {
+        private bool disposed = false;
         private readonly PropertyMap propertyMap = null;
 
         internal delegate void PropertyChangedCallback(TextShadow instance);
@@ -113,5 +114,30 @@ namespace Tizen.NUI
 
             return new PropertyValue(instance.propertyMap);
         }
+
+
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected virtual void Dispose(bool disposing)
+        {
+            if (disposed)
+            {
+                return;
+            }
+            if (disposing)
+            {
+                propertyMap?.Dispose();
+                Color?.Dispose();
+                Offset?.Dispose();
+            }
+            disposed = true;
+        }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void Dispose()
+        {
+            Dispose(true);
+            global::System.GC.SuppressFinalize(this);
+        }
     }
 }
index da51c330f752f4e7035df824517ccdb93905364f..7c2f82bf7bd94673ec9148694b527adcea5dfded 100755 (executable)
@@ -14,6 +14,7 @@
  * limitations under the License.
  *
  */
+using System;
 using System.ComponentModel;
 using Tizen.NUI.BaseComponents;
 
@@ -23,8 +24,9 @@ namespace Tizen.NUI
     /// A class encapsulating the transform map of the visual.
     /// </summary>
     /// <since_tizen> 3 </since_tizen>
-    public class VisualMap
+    public class VisualMap : IDisposable
     {
+        private bool disposed = false;
         /// <summary>
         /// outputVisualMap.
         /// </summary>
@@ -676,5 +678,36 @@ namespace Tizen.NUI
             if (_visualOrigin != null) { _visualTransformMap.Add((int)VisualTransformPropertyType.Origin, new PropertyValue((int)_visualOrigin)); }
             if (_visualAnchorPoint != null) { _visualTransformMap.Add((int)VisualTransformPropertyType.AnchorPoint, new PropertyValue((int)_visualAnchorPoint)); }
         }
+
+
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected virtual void Dispose(bool disposing)
+        {
+            if (disposed)
+            {
+                return;
+            }
+            if (disposing)
+            {
+                _commonlyUsedMap?.Dispose();
+                _mixColor?.Dispose();
+                _outputVisualMap?.Dispose();
+                _shader?.Dispose();
+                _visualOffset?.Dispose();
+                _visualOffsetPolicy?.Dispose();
+                _visualSize?.Dispose();
+                _visualSizePolicy?.Dispose();
+                _visualTransformMap?.Dispose();
+            }
+            disposed = true;
+        }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void Dispose()
+        {
+            Dispose(true);
+            global::System.GC.SuppressFinalize(this);
+        }
     }
 }