[NUI] Reduce build warnings at VisualObjects
authorEunki, Hong <eunkiki.hong@samsung.com>
Tue, 25 Mar 2025 10:36:45 +0000 (19:36 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Thu, 27 Mar 2025 00:43:29 +0000 (09:43 +0900)
- Remove CA1030
- Disable warning for CA2000 for several codes
- Fix unmatched binding function
- Remove CA1001 : Make VisualTransformInfo as disposable

Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
src/Tizen.NUI/src/internal/Interop/Interop.VisualObject.cs
src/Tizen.NUI/src/public/BaseComponents/ViewPublicMethods.cs
src/Tizen.NUI/src/public/Common/Layer.cs
src/Tizen.NUI/src/public/Common/PropertyMap.cs
src/Tizen.NUI/src/public/Visuals/VisualObject/VisualBase.cs
src/Tizen.NUI/src/public/Window/GLWindow.cs
src/Tizen.NUI/src/public/Window/Window.cs

index 95922aa690ffbc20e6835842f82b8c5efdc87d10..8b57bd9673d9bb2fee824982334a0a9f1f996cf7 100755 (executable)
@@ -55,22 +55,22 @@ namespace Tizen.NUI
             public static extern void Detach(global::System.Runtime.InteropServices.HandleRef visualObject);
 
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VisualObject_Raise")]
-            public static extern uint Raise(global::System.Runtime.InteropServices.HandleRef visualObject);
+            public static extern void Raise(global::System.Runtime.InteropServices.HandleRef visualObject);
 
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VisualObject_Lower")]
-            public static extern uint Lower(global::System.Runtime.InteropServices.HandleRef visualObject);
+            public static extern void Lower(global::System.Runtime.InteropServices.HandleRef visualObject);
 
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VisualObject_RaiseToTop")]
-            public static extern uint RaiseToTop(global::System.Runtime.InteropServices.HandleRef visualObject);
+            public static extern void RaiseToTop(global::System.Runtime.InteropServices.HandleRef visualObject);
 
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VisualObject_LowerToBottom")]
-            public static extern uint LowerToBottom(global::System.Runtime.InteropServices.HandleRef visualObject);
+            public static extern void LowerToBottom(global::System.Runtime.InteropServices.HandleRef visualObject);
 
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VisualObject_RaiseAbove")]
-            public static extern uint RaiseAbove(global::System.Runtime.InteropServices.HandleRef visualObject, global::System.Runtime.InteropServices.HandleRef target);
+            public static extern void RaiseAbove(global::System.Runtime.InteropServices.HandleRef visualObject, global::System.Runtime.InteropServices.HandleRef target);
 
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VisualObject_LowerBelow")]
-            public static extern uint LowerBelow(global::System.Runtime.InteropServices.HandleRef visualObject, global::System.Runtime.InteropServices.HandleRef target);
+            public static extern void LowerBelow(global::System.Runtime.InteropServices.HandleRef visualObject, global::System.Runtime.InteropServices.HandleRef target);
         }
     }
 }
index 76dc5e159c8677b15a1474b6b201df1939f421ce..5c3da3e6daa44f7029ddfec4314166e0b0c2f84a 100755 (executable)
@@ -17,6 +17,7 @@
 
 using System;
 using System.ComponentModel;
+using System.Diagnostics.CodeAnalysis;
 using System.Reflection;
 using System.Runtime.InteropServices;
 using Tizen.NUI.Binding;
@@ -380,6 +381,7 @@ namespace Tizen.NUI.BaseComponents
         /// Once a raise or lower API is used, that view will then have an exclusive sibling order independent of insertion.
         /// </remarks>
         /// <since_tizen> 3 </since_tizen>
+        [SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate", Justification = "Method used to raise the object, not event")]
         public void RaiseToTop()
         {
             var parentChildren = GetParent()?.Children;
@@ -798,6 +800,7 @@ namespace Tizen.NUI.BaseComponents
         /// Raise view above the next sibling view.
         /// </summary>
         /// <since_tizen> 9 </since_tizen>
+        [SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate", Justification = "Method used to raise the object, not event")]
         public void Raise()
         {
             var parentChildren = GetParent()?.Children;
@@ -855,6 +858,7 @@ namespace Tizen.NUI.BaseComponents
         /// </remarks>
         /// <param name="target">Will be raised above this view.</param>
         /// <since_tizen> 9 </since_tizen>
+        [SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate", Justification = "Method used to raise the object, not event")]
         public void RaiseAbove(View target)
         {
             var parentChildren = GetParent()?.Children;
index 10b54512ac09b9004f506d50c48a0d84ec342c45..e98a9b34040dd1792b1a7b42f16ccf0e99cc2a0c 100755 (executable)
@@ -17,6 +17,7 @@
 using System;
 using Tizen.NUI.BaseComponents;
 using System.ComponentModel;
+using System.Diagnostics.CodeAnalysis;
 using System.Runtime.InteropServices;
 
 namespace Tizen.NUI
@@ -476,6 +477,7 @@ namespace Tizen.NUI
         /// Increments the depth of the layer.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
+        [SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate", Justification = "Method used to raise the object, not event")]
         public void Raise()
         {
             var parentChildren = window?.LayersChildren;
@@ -515,6 +517,7 @@ namespace Tizen.NUI
         /// Raises the layer to the top.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
+        [SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate", Justification = "Method used to raise the object, not event")]
         public void RaiseToTop()
         {
             var parentChildren = window?.LayersChildren;
index fa107c80d4e1d568cc24f4edaff9184c4df7837f..dd592955d8eb54e8b1799219f2812dcf05af8e62 100755 (executable)
@@ -500,7 +500,9 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public PropertyValue GetValue(uint position)
         {
+#pragma warning disable CA2000 // Dispose objects before losing scope
             PropertyValue ret = new PropertyValue(Interop.PropertyMap.GetValue(SwigCPtr, position), false);
+#pragma warning restore CA2000 // Dispose objects before losing scope
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -513,7 +515,9 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public PropertyKey GetKeyAt(uint position)
         {
+#pragma warning disable CA2000 // Dispose objects before losing scope
             PropertyKey ret = new PropertyKey(Interop.PropertyMap.GetKeyAt(SwigCPtr, position), true);
+#pragma warning restore CA2000 // Dispose objects before losing scope
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -527,7 +531,9 @@ namespace Tizen.NUI
         public PropertyValue Find(string stringKey)
         {
             global::System.IntPtr cPtr = Interop.PropertyMap.Find(SwigCPtr, stringKey);
+#pragma warning disable CA2000 // Dispose objects before losing scope
             PropertyValue ret = (cPtr == global::System.IntPtr.Zero) ? null : new PropertyValue(cPtr, false);
+#pragma warning restore CA2000 // Dispose objects before losing scope
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -541,7 +547,9 @@ namespace Tizen.NUI
         public PropertyValue Find(int key)
         {
             global::System.IntPtr cPtr = Interop.PropertyMap.Find(SwigCPtr, key);
+#pragma warning disable CA2000 // Dispose objects before losing scope
             PropertyValue ret = (cPtr == global::System.IntPtr.Zero) ? null : new PropertyValue(cPtr, false);
+#pragma warning restore CA2000 // Dispose objects before losing scope
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -556,7 +564,9 @@ namespace Tizen.NUI
         public PropertyValue Find(int indexKey, string stringKey)
         {
             global::System.IntPtr cPtr = Interop.PropertyMap.Find(SwigCPtr, indexKey, stringKey);
+#pragma warning disable CA2000 // Dispose objects before losing scope
             PropertyValue ret = (cPtr == global::System.IntPtr.Zero) ? null : new PropertyValue(cPtr, false);
+#pragma warning restore CA2000 // Dispose objects before losing scope
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -595,7 +605,9 @@ namespace Tizen.NUI
         /// <returns>The value for the element with the specified key.</returns>
         internal PropertyValue ValueOfIndex(string key)
         {
+#pragma warning disable CA2000 // Dispose objects before losing scope
             PropertyValue ret = new PropertyValue(Interop.PropertyMap.ValueOfIndex(SwigCPtr, key), false);
+#pragma warning restore CA2000 // Dispose objects before losing scope
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -607,7 +619,9 @@ namespace Tizen.NUI
         /// <returns>The value for the element with the specified key.</returns>
         internal PropertyValue ValueOfIndex(int key)
         {
+#pragma warning disable CA2000 // Dispose objects before losing scope
             PropertyValue ret = new PropertyValue(Interop.PropertyMap.ValueOfIndex(SwigCPtr, key), false);
+#pragma warning restore CA2000 // Dispose objects before losing scope
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
index 1973957d6eed8166da2461886725b8c270d24312..c3ae31941a5c0034b7059b39a5b234636f1efe6c 100644 (file)
@@ -17,6 +17,7 @@ using System.Runtime.InteropServices;
 using System.Collections.Generic;
 using System.Linq;
 using System.ComponentModel;
+using System.Diagnostics.CodeAnalysis;
 
 namespace Tizen.NUI.Visuals
 {
@@ -51,7 +52,7 @@ namespace Tizen.NUI.Visuals
 
         private bool visualFittingModeApplied = false; // Whether we use fitting mode, or DontCare.
 
-        internal struct VisualTransformInfo
+        internal class VisualTransformInfo : System.IDisposable
         {
             public float width;
             public float height;
@@ -72,6 +73,13 @@ namespace Tizen.NUI.Visuals
             public PropertyMap cachedVisualTransformPropertyMap;
 
             internal bool changed;
+
+            public VisualTransformInfo()
+            {
+                Clear();
+            }
+
+            ~VisualTransformInfo() => Dispose(false);
             
             public void Clear()
             {
@@ -97,6 +105,20 @@ namespace Tizen.NUI.Visuals
                 changed = true;
             }
 
+            public void Dispose()
+            {
+                Dispose(true);
+                global::System.GC.SuppressFinalize(this);
+            }
+
+            protected virtual void Dispose(bool disposing)
+            {
+                if (disposing)
+                {
+                    cachedVisualTransformPropertyMap?.Dispose();
+                }
+            }
+
             internal PropertyMap ConvertToPropertyMap()
             {
                 if (cachedVisualTransformPropertyMap == null)
@@ -107,19 +129,20 @@ namespace Tizen.NUI.Visuals
                 cachedVisualTransformPropertyMap.Clear();
 
                 // TODO : Let we optimize here after native map add API binded
-                cachedVisualTransformPropertyMap.Add((int)VisualTransformPropertyType.Size, new PropertyValue(width, height))
-                                                .Add((int)VisualTransformPropertyType.Offset, new PropertyValue(offsetX, offsetY))
-                                                .Add((int)VisualTransformPropertyType.SizePolicy, new PropertyValue((float)widthPolicy, (float)heightPolicy))
-                                                .Add((int)VisualTransformPropertyType.OffsetPolicy, new PropertyValue((float)offsetXPolicy, (float)offsetYPolicy))
-                                                .Add((int)VisualTransformPropertyType.Origin, new PropertyValue((int)origin))
-                                                .Add((int)VisualTransformPropertyType.AnchorPoint, new PropertyValue((int)pivotPoint))
-                                                .Add((int)VisualTransformPropertyType.ExtraSize, new PropertyValue(extraWidth, extraHeight));
+                cachedVisualTransformPropertyMap.Append((int)VisualTransformPropertyType.Size, new UIVector2(width, height))
+                                                .Append((int)VisualTransformPropertyType.Offset, new UIVector2(offsetX, offsetY))
+                                                .Append((int)VisualTransformPropertyType.SizePolicy, new UIVector2((float)widthPolicy, (float)heightPolicy))
+                                                .Append((int)VisualTransformPropertyType.OffsetPolicy, new UIVector2((float)offsetXPolicy, (float)offsetYPolicy))
+                                                .Add((int)VisualTransformPropertyType.Origin, (int)origin)
+                                                .Add((int)VisualTransformPropertyType.AnchorPoint, (int)pivotPoint)
+                                                .Append((int)VisualTransformPropertyType.ExtraSize, new UIVector2(extraWidth, extraHeight));
 
                 return cachedVisualTransformPropertyMap;
             }
 
             internal void ConvertFromPropertyMap(PropertyMap inputMap)
             {
+#pragma warning disable CA2000 // Dispose objects before losing scope
                 PropertyValue value = null;
 
                 if ((value = inputMap?.Find((int)VisualTransformPropertyType.Size)) != null)
@@ -184,6 +207,7 @@ namespace Tizen.NUI.Visuals
                     }
                 }
                 value?.Dispose();
+#pragma warning restore CA2000 // Dispose objects before losing scope
             }
         };
         internal VisualTransformInfo transformInfo;
@@ -196,7 +220,7 @@ namespace Tizen.NUI.Visuals
 
         internal VisualBase(global::System.IntPtr cPtr, bool cMemoryOwn, bool cRegister) : base(cPtr, cMemoryOwn, cRegister)
         {
-            transformInfo.Clear();
+            transformInfo = new VisualTransformInfo();
         }
         #endregion
 
@@ -310,11 +334,16 @@ namespace Tizen.NUI.Visuals
                 UpdateVisualProperty((int)Tizen.NUI.Visual.Property.MixColor, value, false);
 
                 // warning : We should set cached Opacity after set MixColor.
-                UpdateVisualProperty((int)Tizen.NUI.Visual.Property.Opacity, value.A, false);
+                if (value != null)
+                {
+                    UpdateVisualProperty((int)Tizen.NUI.Visual.Property.Opacity, value.A, false);
+                }
             }
             get
             {
+#pragma warning disable CA2000 // Dispose objects before losing scope
                 Tizen.NUI.Color ret = new Tizen.NUI.Color(1.0f, 1.0f, 1.0f, 1.0f);
+#pragma warning restore CA2000 // Dispose objects before losing scope
                 using var propertyValue = GetCachedVisualProperty((int)Tizen.NUI.Visual.Property.MixColor);
                 propertyValue?.Get(ret);
                 return ret;
@@ -734,6 +763,7 @@ namespace Tizen.NUI.Visuals
         /// Raise above the next sibling visual object
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
+        [SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate", Justification = "Method used to raise the object, not event")]
         public void Raise()
         {
             Interop.VisualObject.Raise(SwigCPtr);
@@ -754,6 +784,7 @@ namespace Tizen.NUI.Visuals
         /// Raise above all other sibling visual objects
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
+        [SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate", Justification = "Method used to raise the object, not event")]
         public void RaiseToTop()
         {
             Interop.VisualObject.RaiseToTop(SwigCPtr);
@@ -774,6 +805,7 @@ namespace Tizen.NUI.Visuals
         /// Raise above target visual objects. No effects if visual object is already above target.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
+        [SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate", Justification = "Method used to raise the object, not event")]
         public void RaiseAbove(Visuals.VisualBase target)
         {
             Interop.VisualObject.RaiseAbove(SwigCPtr, Visuals.VisualBase.getCPtr(target));
@@ -819,7 +851,9 @@ namespace Tizen.NUI.Visuals
                 }
                 else
                 {
+#pragma warning disable CA2000 // Dispose objects before losing scope
                     ret = new Visuals.VisualObjectsContainer(cPtr, true);
+#pragma warning restore CA2000 // Dispose objects before losing scope
                 }
             }
             NDalicPINVOKE.ThrowExceptionIfExists();
@@ -1130,15 +1164,17 @@ namespace Tizen.NUI.Visuals
                 // Since if visual is already under some VisualObjectsContainer,
                 // it will never be GC.
                 Detach();
+
+                changedPropertyMap?.Dispose();
+                changedPropertyMap = null;
+                cachedVisualPropertyMap?.Dispose();
+                cachedVisualPropertyMap = null;
+                transformInfo?.Dispose();
+                transformInfo = null;
             }
 
             visualCreationRequiredFlag = false;
 
-            changedPropertyMap?.Dispose();
-            changedPropertyMap = null;
-            cachedVisualPropertyMap?.Dispose();
-            cachedVisualPropertyMap = null;
-
             base.Dispose(type);
         }
         #endregion
index a5c946759ff61c4aa1169ba34aff18b342215ad2..b92f98041034b4ef55f078825421df59e58827e2 100755 (executable)
@@ -20,6 +20,7 @@ extern alias TizenSystemInformation;
 using System;
 using System.ComponentModel;
 using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
 using System.Runtime.InteropServices;
 
 namespace Tizen.NUI
@@ -173,6 +174,7 @@ namespace Tizen.NUI
         /// Raises the window to the top of the window stack.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
+        [SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate", Justification = "Method used to raise the object, not event")]
         public void Raise()
         {
             Interop.GLWindow.GlWindowRaise(SwigCPtr);
index cf165fce230575a18d2d7dd8d8b21e92f3d92799..560274b619481023e4a7dd628e5de43a9663f4af 100755 (executable)
@@ -21,6 +21,7 @@ using TizenSystemInformation.Tizen.System;
 using System;
 using System.ComponentModel;
 using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
 using System.Runtime.InteropServices;
 using Tizen.NUI.BaseComponents;
 using Tizen.Common;
@@ -990,6 +991,7 @@ namespace Tizen.NUI
         /// Raises the window to the top of the window stack.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
+        [SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate", Justification = "Method used to raise the object, not event")]
         public void Raise()
         {
             Interop.Window.Raise(SwigCPtr);