[NUI] Fix CA2000 warning issues of View and ViewImpl.
authorguowei.wang <guowei.wang@samsung.com>
Wed, 6 Jan 2021 10:10:32 +0000 (18:10 +0800)
committerhuiyueun <35286162+huiyueun@users.noreply.github.com>
Mon, 11 Jan 2021 05:49:43 +0000 (14:49 +0900)
src/Tizen.NUI/src/internal/ViewImpl.cs
src/Tizen.NUI/src/public/BaseComponents/View.cs

index 62c5416..aa48c0c 100755 (executable)
@@ -570,27 +570,48 @@ namespace Tizen.NUI
 
         private void SwigDirectorOnPropertySet(int index, global::System.IntPtr propertyValue)
         {
-            OnPropertySet(index, new PropertyValue(propertyValue, true));
+            using (PropertyValue setValue = new PropertyValue(propertyValue, true))
+            {
+                OnPropertySet(index, setValue);
+            }
         }
 
         private void SwigDirectorOnSizeSet(global::System.IntPtr targetSize)
         {
-            OnSizeSet(new Vector3(targetSize, false));
+            using (Vector3 setValue = new Vector3(targetSize, false))
+            {
+                OnSizeSet(setValue);
+            }
         }
 
         private void SwigDirectorOnSizeAnimation(global::System.IntPtr animation, global::System.IntPtr targetSize)
         {
-            OnSizeAnimation(new Animation(animation, false), new Vector3(targetSize, false));
+            using (Animation setAnimation = new Animation(animation, false))
+            {
+                using (Vector3 setTargetSize = new Vector3(targetSize, false))
+                {
+                    OnSizeAnimation(setAnimation, setTargetSize);
+                }
+            }
         }
 
         private bool SwigDirectorOnKeyEvent(global::System.IntPtr arg0)
         {
-            return OnKeyEvent(new Key(arg0, false));
+            using (Key setKey = new Key(arg0, false))
+            {
+                return OnKeyEvent(setKey);
+            }
         }
 
         private void SwigDirectorOnRelayout(global::System.IntPtr size, global::System.IntPtr container)
         {
-            OnRelayout(new Vector2(size, false), new RelayoutContainer(container, false));
+            using (Vector2 setSize = new Vector2(size, false))
+            {
+                using (RelayoutContainer setContainer = new RelayoutContainer(container, false))
+                {
+                    OnRelayout(setSize, setContainer);
+                }
+            }
         }
 
         private void SwigDirectorOnSetResizePolicy(int policy, int dimension)
@@ -664,7 +685,10 @@ namespace Tizen.NUI
 
         private bool SwigDirectorOnAccessibilityPan(global::System.IntPtr gesture)
         {
-            return OnAccessibilityPan(new PanGesture(gesture, true));
+            using (PanGesture setPanGesture = new PanGesture(gesture, true)) 
+            {
+                return OnAccessibilityPan(setPanGesture);
+            }
         }
 
         private bool SwigDirectorOnAccessibilityValueChange(bool isIncrease)
@@ -704,32 +728,50 @@ namespace Tizen.NUI
 
         private void SwigDirectorOnPinch(global::System.IntPtr pinch)
         {
-            OnPinch(new PinchGesture(pinch, false));
+            using (PinchGesture setPinch = new PinchGesture(pinch, false))
+            {
+                OnPinch(setPinch);
+            }
         }
 
         private void SwigDirectorOnPan(global::System.IntPtr pan)
         {
-            OnPan(new PanGesture(pan, false));
+            using (PanGesture setPan = new PanGesture(pan, false))
+            {
+                OnPan(setPan);
+            }
         }
 
         private void SwigDirectorOnTap(global::System.IntPtr tap)
         {
-            OnTap(new TapGesture(tap, false));
+            using (TapGesture setTapGesture = new TapGesture(tap, false))
+            {
+                OnTap(setTapGesture);
+            }
         }
 
         private void SwigDirectorOnLongPress(global::System.IntPtr longPress)
         {
-            OnLongPress(new LongPressGesture(longPress, false));
+            using (LongPressGesture setLongPress = new LongPressGesture(longPress, false))
+            {
+                OnLongPress(setLongPress);
+            }
         }
 
         private void SwigDirectorSignalConnected(global::System.IntPtr slotObserver, global::System.IntPtr callback)
         {
-            SignalConnected((slotObserver == global::System.IntPtr.Zero) ? null : new SlotObserver(slotObserver, false), (callback == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_Dali__CallbackBase(callback));
+            using (SlotObserver setSlotObserver = new SlotObserver(slotObserver, false))
+            {
+                SignalConnected((slotObserver == global::System.IntPtr.Zero) ? null : setSlotObserver, (callback == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_Dali__CallbackBase(callback));
+            }
         }
 
         private void SwigDirectorSignalDisconnected(global::System.IntPtr slotObserver, global::System.IntPtr callback)
         {
-            SignalDisconnected((slotObserver == global::System.IntPtr.Zero) ? null : new SlotObserver(slotObserver, false), (callback == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_Dali__CallbackBase(callback));
+            using (SlotObserver setSlotObserver = new SlotObserver(slotObserver, false))
+            {
+                SignalDisconnected((slotObserver == global::System.IntPtr.Zero) ? null : setSlotObserver, (callback == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_Dali__CallbackBase(callback));
+            }
         }
 
         /// <since_tizen> 3 </since_tizen>
index ade387f..1570215 100755 (executable)
@@ -536,8 +536,11 @@ namespace Tizen.NUI.BaseComponents
             }
             set
             {
-                SetProperty(View.Property.TOOLTIP, new Tizen.NUI.PropertyValue(value));
-                NotifyPropertyChanged();
+                using (PropertyValue setValue = new Tizen.NUI.PropertyValue(value))
+                {
+                    SetProperty(View.Property.TOOLTIP, setValue);
+                    NotifyPropertyChanged();
+                }
             }
         }
 
@@ -908,9 +911,15 @@ namespace Tizen.NUI.BaseComponents
         {
             get
             {
-                Vector2 temp = new Vector2(0.0f, 0.0f);
-                GetProperty(View.Property.ScreenPosition).Get(temp);
-                return temp;
+                using (PropertyValue screenPosition = GetProperty(View.Property.ScreenPosition)) 
+                {
+                    using (Vector2 vectorValue = new Vector2(0.0f, 0.0f))
+                    {
+                        Vector2 position = vectorValue;
+                        screenPosition?.Get(position);
+                        return position;
+                    }
+                }
             }
         }
 
@@ -950,14 +959,20 @@ namespace Tizen.NUI.BaseComponents
         {
             get
             {
-                bool temp = false;
-                GetProperty(View.Property.PositionUsesAnchorPoint).Get(out temp);
-                return temp;
+                using (PropertyValue positionUsesAnchor = GetProperty(View.Property.PositionUsesAnchorPoint))
+                {
+                    bool returnValue = false;
+                    positionUsesAnchor?.Get(out returnValue);
+                    return returnValue;
+                }
             }
             set
             {
-                SetProperty(View.Property.PositionUsesAnchorPoint, new Tizen.NUI.PropertyValue(value));
-                NotifyPropertyChanged();
+                using (PropertyValue setValue = new Tizen.NUI.PropertyValue(value))
+                {
+                    SetProperty(View.Property.PositionUsesAnchorPoint, setValue);
+                    NotifyPropertyChanged();
+                }
             }
         }
 
@@ -1040,10 +1055,13 @@ namespace Tizen.NUI.BaseComponents
         {
             get
             {
-                Vector3 temp = new Vector3(Interop.Actor.GetNaturalSize(SwigCPtr), true);
-                if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
+                using (Vector3 vectorValue = new Vector3(Interop.Actor.GetNaturalSize(SwigCPtr), true))
+                {
+                    Vector3 naturalSize = vectorValue;
+                    if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
 
-                return new Size2D((int)temp.Width, (int)temp.Height);
+                    return new Size2D((int)naturalSize?.Width, (int)naturalSize?.Height);
+                }
             }
         }
 
@@ -1239,9 +1257,15 @@ namespace Tizen.NUI.BaseComponents
         {
             get
             {
-                Vector3 temp = new Vector3(0.0f, 0.0f, 0.0f);
-                GetProperty(View.Property.WorldPosition).Get(temp);
-                return temp;
+                using (PropertyValue worldPos = GetProperty(View.Property.WorldPosition))
+                {
+                    using (Vector3 vectorValue = new Vector3(0.0f, 0.0f, 0.0f))
+                    {
+                        Vector3 position = vectorValue;
+                        worldPos?.Get(position);
+                        return position;
+                    }
+                }
             }
         }
 
@@ -1279,9 +1303,14 @@ namespace Tizen.NUI.BaseComponents
         {
             get
             {
-                Rotation temp = new Rotation();
-                GetProperty(View.Property.WorldOrientation).Get(temp);
-                return temp;
+                using (PropertyValue worldOri = GetProperty(View.Property.WorldOrientation))
+                {
+                    using (Rotation rotation = new Rotation())
+                    {
+                        worldOri?.Get(rotation);
+                        return rotation;
+                    }
+                }
             }
         }
 
@@ -1383,9 +1412,14 @@ namespace Tizen.NUI.BaseComponents
         {
             get
             {
-                Vector3 temp = new Vector3(0.0f, 0.0f, 0.0f);
-                GetProperty(View.Property.WorldScale).Get(temp);
-                return temp;
+                using (PropertyValue worldScale = GetProperty(View.Property.WorldScale))
+                {
+                    using (Vector3 vectorValue = new Vector3(0.0f, 0.0f, 0.0f))
+                    {
+                        worldScale?.Get(vectorValue);
+                        return vectorValue;
+                    }
+                }
             }
         }
 
@@ -1406,9 +1440,12 @@ namespace Tizen.NUI.BaseComponents
         {
             get
             {
-                bool temp = false;
-                GetProperty(View.Property.VISIBLE).Get(out temp);
-                return temp;
+                using (PropertyValue visible = GetProperty(View.Property.VISIBLE))
+                {
+                    bool isVisible = false;
+                    visible?.Get(out isVisible);
+                    return isVisible;
+                }
             }
         }
 
@@ -1420,9 +1457,14 @@ namespace Tizen.NUI.BaseComponents
         {
             get
             {
-                Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
-                GetProperty(View.Property.WorldColor).Get(temp);
-                return temp;
+                using (PropertyValue worldColor = GetProperty(View.Property.WorldColor))
+                {
+                    using (Vector4 vectorValue = new Vector4(0.0f, 0.0f, 0.0f, 0.0f))
+                    {
+                        worldColor?.Get(vectorValue);
+                        return vectorValue;
+                    }
+                }
             }
         }
 
@@ -1838,14 +1880,22 @@ namespace Tizen.NUI.BaseComponents
         {
             get
             {
-                Position temp = new Position(0.0f, 0.0f, 0.0f);
-                GetProperty(View.Property.AnchorPoint).Get(temp);
-                return new Position(OnAnchorPointChanged, temp.X, temp.Y, temp.Z);
+                using (PropertyValue anchorPoint = GetProperty(View.Property.AnchorPoint))
+                {
+                    using (Position position = new Position(0.0f, 0.0f, 0.0f))
+                    { 
+                        anchorPoint?.Get(position);
+                        return new Position(OnAnchorPointChanged, position.X, position.Y, position.Z);
+                    }
+                }
             }
             set
             {
-                SetProperty(View.Property.AnchorPoint, new Tizen.NUI.PropertyValue(value));
-                NotifyPropertyChanged();
+                using (PropertyValue setValue = new Tizen.NUI.PropertyValue(value))
+                {
+                    SetProperty(View.Property.AnchorPoint, setValue);
+                    NotifyPropertyChanged();
+                }
             }
         }
 
@@ -1896,8 +1946,11 @@ namespace Tizen.NUI.BaseComponents
 
                 if (basehandle is Layer layer)
                 {
-                    ret = new View(Layer.getCPtr(layer).Handle, false);
-                    NUILog.Error("This Parent property is deprecated, shoud do not be used");
+                    using (View view = new View(Layer.getCPtr(layer).Handle, false))
+                    {
+                        ret = view;
+                        NUILog.Error("This Parent property is deprecated, shoud do not be used");
+                    }
                 }
                 else
                 {
@@ -2118,15 +2171,23 @@ namespace Tizen.NUI.BaseComponents
         {
             get
             {
-                Extents temp = new Extents(0, 0, 0, 0);
-                GetProperty(View.Property.PADDING).Get(temp);
-                return new Extents(OnPaddingEXChanged, temp.Start, temp.End, temp.Top, temp.Bottom);
+                using (PropertyValue padding = GetProperty(View.Property.PADDING))
+                {
+                    using (Extents extents = new Extents(0, 0, 0, 0))
+                    {
+                        padding?.Get(extents);
+                        return new Extents(OnPaddingEXChanged, extents.Start, extents.End, extents.Top, extents.Bottom);
+                    }
+                }
             }
             set
             {
-                SetProperty(View.Property.PADDING, new Tizen.NUI.PropertyValue(value));
-                NotifyPropertyChanged();
-                layout?.RequestLayout();
+                using (PropertyValue setValue = new Tizen.NUI.PropertyValue(value))
+                {
+                    SetProperty(View.Property.PADDING, setValue);
+                    NotifyPropertyChanged();
+                    layout?.RequestLayout();
+                }
             }
         }
 
@@ -2281,13 +2342,19 @@ namespace Tizen.NUI.BaseComponents
                 backgroundImageSynchronosLoading = value;
 
                 string bgUrl = null;
-                Background.Find(ImageVisualProperty.URL)?.Get(out bgUrl);
+                using (PropertyValue url = Background.Find(ImageVisualProperty.URL))
+                {
+                    url?.Get(out bgUrl);
+                }
 
                 if (!string.IsNullOrEmpty(bgUrl))
                 {
                     PropertyMap bgMap = this.Background;
-                    bgMap.Add("synchronousLoading", new PropertyValue(backgroundImageSynchronosLoading));
-                    Background = bgMap;
+                    using (PropertyValue addedProperty = new PropertyValue(backgroundImageSynchronosLoading))
+                    {
+                        bgMap.Add("synchronousLoading", addedProperty);
+                        Background = bgMap;
+                    }
                 }
             }
         }
@@ -2370,14 +2437,20 @@ namespace Tizen.NUI.BaseComponents
         {
             get
             {
-                bool temp = false;
-                GetProperty(View.Property.CaptureAllTouchAfterStart).Get(out temp);
-                return temp;
+                using (PropertyValue captureAllTouch = GetProperty(View.Property.CaptureAllTouchAfterStart))
+                {
+                    bool isGrabTouch = false;
+                    captureAllTouch?.Get(out isGrabTouch);
+                    return isGrabTouch;
+                }
             }
             set
             {
-                SetProperty(View.Property.CaptureAllTouchAfterStart, new Tizen.NUI.PropertyValue(value));
-                NotifyPropertyChanged();
+                using (PropertyValue setValue = new Tizen.NUI.PropertyValue(value))
+                {
+                    SetProperty(View.Property.CaptureAllTouchAfterStart, setValue);
+                    NotifyPropertyChanged();
+                }
             }
         }
 
@@ -2391,14 +2464,20 @@ namespace Tizen.NUI.BaseComponents
         {
             get
             {
-                int temp = 0;
-                GetProperty(View.Property.BlendEquation).Get(out temp);
-                return (BlendEquationType)temp;
+                using (PropertyValue blendEquation = GetProperty(View.Property.BlendEquation))
+                {
+                    int type = 0;
+                    blendEquation?.Get(out type);
+                    return (BlendEquationType)type;
+                }
             }
             set
             {
-                SetProperty(View.Property.BlendEquation, new Tizen.NUI.PropertyValue((int)value));
-                NotifyPropertyChanged();
+                using (PropertyValue setValue = new Tizen.NUI.PropertyValue((int)value))
+                {
+                    SetProperty(View.Property.BlendEquation, setValue);
+                    NotifyPropertyChanged();
+                }
             }
         }