From 4bdcd6168960f92abf0d46cf2004a6fc48ca25b2 Mon Sep 17 00:00:00 2001 From: zhouleonlei Date: Wed, 6 Jan 2021 14:51:21 +0800 Subject: [PATCH] [NUI] Fix CA2000 Warnings --- .../src/public/LongPressGestureDetector.cs | 16 +++++++--- src/Tizen.NUI/src/public/PanGestureDetector.cs | 37 ++++++++++++++++------ src/Tizen.NUI/src/public/PinchGestureDetector.cs | 13 +++++--- src/Tizen.NUI/src/public/PropertyNotification.cs | 8 +++-- .../src/public/RotationGestureDetector.cs | 13 +++++--- src/Tizen.NUI/src/public/Shader.cs | 8 +++-- src/Tizen.NUI/src/public/StyleManager.cs | 10 ++++-- src/Tizen.NUI/src/public/TTSPlayer.cs | 10 ++++-- src/Tizen.NUI/src/public/TapGestureDetector.cs | 13 +++++--- src/Tizen.NUI/src/public/Timer.cs | 14 +++++--- src/Tizen.NUI/src/public/Utility/TextPageUtil.cs | 4 ++- 11 files changed, 103 insertions(+), 43 deletions(-) diff --git a/src/Tizen.NUI/src/public/LongPressGestureDetector.cs b/src/Tizen.NUI/src/public/LongPressGestureDetector.cs index 632b1fb..09bae0a 100755 --- a/src/Tizen.NUI/src/public/LongPressGestureDetector.cs +++ b/src/Tizen.NUI/src/public/LongPressGestureDetector.cs @@ -85,6 +85,7 @@ namespace Tizen.NUI [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void DetectedCallbackType(IntPtr actor, IntPtr longPressGesture); private DetectedCallbackType _detectedCallback; + private LongPressGestureDetectedSignal detectedSignal; /// /// This signal is emitted when the specified long press is detected on the attached view. @@ -98,7 +99,8 @@ namespace Tizen.NUI if (_detectedEventHandler == null) { _detectedCallback = OnLongPressGestureDetected; - DetectedSignal().Connect(_detectedCallback); + detectedSignal = DetectedSignal(); + detectedSignal.Connect(_detectedCallback); } _detectedEventHandler += value; @@ -108,9 +110,11 @@ namespace Tizen.NUI { _detectedEventHandler -= value; - if (_detectedEventHandler == null && DetectedSignal().Empty() == false) + if (_detectedEventHandler == null && detectedSignal?.Empty() == false) { - DetectedSignal().Disconnect(_detectedCallback); + detectedSignal.Disconnect(_detectedCallback); + detectedSignal.Dispose(); + detectedSignal = null; } } } @@ -204,9 +208,11 @@ namespace Tizen.NUI [EditorBrowsable(EditorBrowsableState.Never)] protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr) { - if (_detectedEventHandler == null && DetectedSignal().Empty() == false) + if (_detectedEventHandler == null && detectedSignal?.Empty() == false) { - DetectedSignal().Disconnect(_detectedCallback); + detectedSignal.Disconnect(_detectedCallback); + detectedSignal.Dispose(); + detectedSignal = null; } Interop.LongPressGestureDetector.DeleteLongPressGestureDetector(swigCPtr); } diff --git a/src/Tizen.NUI/src/public/PanGestureDetector.cs b/src/Tizen.NUI/src/public/PanGestureDetector.cs index 05bbf89..3fa4db3 100755 --- a/src/Tizen.NUI/src/public/PanGestureDetector.cs +++ b/src/Tizen.NUI/src/public/PanGestureDetector.cs @@ -58,6 +58,7 @@ namespace Tizen.NUI [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void DetectedCallbackType(IntPtr actor, IntPtr panGesture); private DetectedCallbackType _detectedCallback; + private PanGestureDetectedSignal detectedSignal; /// /// This signal is emitted when the specified pan is detected on the attached view. @@ -71,7 +72,8 @@ namespace Tizen.NUI if (_detectedEventHandler == null) { _detectedCallback = OnPanGestureDetected; - DetectedSignal().Connect(_detectedCallback); + detectedSignal = DetectedSignal(); + detectedSignal.Connect(_detectedCallback); } _detectedEventHandler += value; @@ -81,9 +83,11 @@ namespace Tizen.NUI { _detectedEventHandler -= value; - if (_detectedEventHandler == null && DetectedSignal().Empty() == false) + if (_detectedEventHandler == null && detectedSignal?.Empty() == false) { - DetectedSignal().Disconnect(_detectedCallback); + detectedSignal.Disconnect(_detectedCallback); + detectedSignal.Dispose(); + detectedSignal = null; } } } @@ -225,7 +229,9 @@ namespace Tizen.NUI get { Vector2 temp = new Vector2(0.0f, 0.0f); - Tizen.NUI.Object.GetProperty(SwigCPtr, PanGestureDetector.Property.ScreenDisplacement).Get(temp); + var pValue = Tizen.NUI.Object.GetProperty(SwigCPtr, PanGestureDetector.Property.ScreenDisplacement); + pValue.Get(temp); + pValue.Dispose(); return temp; } } @@ -240,7 +246,9 @@ namespace Tizen.NUI get { Vector2 temp = new Vector2(0.0f, 0.0f); - Tizen.NUI.Object.GetProperty(SwigCPtr, PanGestureDetector.Property.ScreenVelocity).Get(temp); + var pValue = Tizen.NUI.Object.GetProperty(SwigCPtr, PanGestureDetector.Property.ScreenVelocity); + pValue.Get(temp); + pValue.Dispose(); return temp; } } @@ -255,7 +263,9 @@ namespace Tizen.NUI get { Vector2 temp = new Vector2(0.0f, 0.0f); - Tizen.NUI.Object.GetProperty(SwigCPtr, PanGestureDetector.Property.LocalPosition).Get(temp); + var pValue = Tizen.NUI.Object.GetProperty(SwigCPtr, PanGestureDetector.Property.LocalPosition); + pValue.Get(temp); + pValue.Dispose(); return temp; } } @@ -270,7 +280,9 @@ namespace Tizen.NUI get { Vector2 temp = new Vector2(0.0f, 0.0f); - Tizen.NUI.Object.GetProperty(SwigCPtr, PanGestureDetector.Property.LocalDisplacement).Get(temp); + var pValue = Tizen.NUI.Object.GetProperty(SwigCPtr, PanGestureDetector.Property.LocalDisplacement); + pValue.Get(temp); + pValue.Dispose(); return temp; } } @@ -285,7 +297,9 @@ namespace Tizen.NUI get { Vector2 temp = new Vector2(0.0f, 0.0f); - Tizen.NUI.Object.GetProperty(SwigCPtr, PanGestureDetector.Property.LocalVelocity).Get(temp); + var pValue = Tizen.NUI.Object.GetProperty(SwigCPtr, PanGestureDetector.Property.LocalVelocity); + pValue.Get(temp); + pValue.Dispose(); return temp; } } @@ -300,7 +314,9 @@ namespace Tizen.NUI get { bool temp = false; - Tizen.NUI.Object.GetProperty(SwigCPtr, PanGestureDetector.Property.PANNING).Get(out temp); + var pValue = Tizen.NUI.Object.GetProperty(SwigCPtr, PanGestureDetector.Property.PANNING); + pValue.Get(out temp); + pValue.Dispose(); return temp; } } @@ -519,7 +535,8 @@ namespace Tizen.NUI { if (_detectedCallback != null) { - DetectedSignal().Disconnect(_detectedCallback); + detectedSignal?.Disconnect(_detectedCallback); + detectedSignal?.Dispose(); } Interop.PanGestureDetector.DeletePanGestureDetector(swigCPtr); diff --git a/src/Tizen.NUI/src/public/PinchGestureDetector.cs b/src/Tizen.NUI/src/public/PinchGestureDetector.cs index f8fdb00..a0932cd 100755 --- a/src/Tizen.NUI/src/public/PinchGestureDetector.cs +++ b/src/Tizen.NUI/src/public/PinchGestureDetector.cs @@ -58,6 +58,7 @@ namespace Tizen.NUI [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void DetectedCallbackType(IntPtr actor, IntPtr pinchGesture); private DetectedCallbackType _detectedCallback; + private PinchGestureDetectedSignal detectedSignal; /// /// This signal is emitted when the specified pinch is detected on the attached view. @@ -71,7 +72,8 @@ namespace Tizen.NUI if (_detectedEventHandler == null) { _detectedCallback = OnPinchGestureDetected; - DetectedSignal().Connect(_detectedCallback); + detectedSignal = DetectedSignal(); + detectedSignal.Connect(_detectedCallback); } _detectedEventHandler += value; @@ -81,9 +83,11 @@ namespace Tizen.NUI { _detectedEventHandler -= value; - if (_detectedEventHandler == null && DetectedSignal().Empty() == false) + if (_detectedEventHandler == null && detectedSignal?.Empty() == false) { - DetectedSignal().Disconnect(_detectedCallback); + detectedSignal.Disconnect(_detectedCallback); + detectedSignal.Dispose(); + detectedSignal = null; } } } @@ -128,7 +132,8 @@ namespace Tizen.NUI { if (_detectedCallback != null) { - DetectedSignal().Disconnect(_detectedCallback); + detectedSignal?.Disconnect(_detectedCallback); + detectedSignal?.Dispose(); } Interop.PinchGesture.DeletePinchGestureDetector(swigCPtr); diff --git a/src/Tizen.NUI/src/public/PropertyNotification.cs b/src/Tizen.NUI/src/public/PropertyNotification.cs index 48eea3e..4a5ffff 100755 --- a/src/Tizen.NUI/src/public/PropertyNotification.cs +++ b/src/Tizen.NUI/src/public/PropertyNotification.cs @@ -31,6 +31,7 @@ namespace Tizen.NUI private DaliEventHandler _propertyNotificationNotifyEventHandler; private NotifyEventCallbackDelegate _propertyNotificationNotifyEventCallbackDelegate; + private PropertyNotifySignal notifySignal; /// /// Create a instance of PropertyNotification. @@ -72,7 +73,8 @@ namespace Tizen.NUI _propertyNotificationNotifyEventHandler += value; _propertyNotificationNotifyEventCallbackDelegate = new NotifyEventCallbackDelegate(OnPropertyNotificationNotify); - this.NotifySignal().Connect(_propertyNotificationNotifyEventCallbackDelegate); + notifySignal = this.NotifySignal(); + notifySignal.Connect(_propertyNotificationNotifyEventCallbackDelegate); } } @@ -80,7 +82,9 @@ namespace Tizen.NUI { if (_propertyNotificationNotifyEventHandler != null) { - this.NotifySignal().Disconnect(_propertyNotificationNotifyEventCallbackDelegate); + notifySignal?.Disconnect(_propertyNotificationNotifyEventCallbackDelegate); + notifySignal?.Dispose(); + notifySignal = null; } _propertyNotificationNotifyEventHandler -= value; diff --git a/src/Tizen.NUI/src/public/RotationGestureDetector.cs b/src/Tizen.NUI/src/public/RotationGestureDetector.cs index 43a06da..291f101 100755 --- a/src/Tizen.NUI/src/public/RotationGestureDetector.cs +++ b/src/Tizen.NUI/src/public/RotationGestureDetector.cs @@ -58,6 +58,7 @@ namespace Tizen.NUI [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void DetectedCallbackType(IntPtr actor, IntPtr rotationGesture); private DetectedCallbackType _detectedCallback; + private RotationGestureDetectedSignal detectedSignal; /// /// This signal is emitted when the specified rotation is detected on the attached view. @@ -71,7 +72,8 @@ namespace Tizen.NUI if (_detectedEventHandler == null) { _detectedCallback = OnRotationGestureDetected; - DetectedSignal().Connect(_detectedCallback); + detectedSignal = DetectedSignal(); + detectedSignal.Connect(_detectedCallback); } _detectedEventHandler += value; @@ -81,9 +83,11 @@ namespace Tizen.NUI { _detectedEventHandler -= value; - if (_detectedEventHandler == null && DetectedSignal().Empty() == false) + if (_detectedEventHandler == null && detectedSignal?.Empty() == false) { - DetectedSignal().Disconnect(_detectedCallback); + detectedSignal.Disconnect(_detectedCallback); + detectedSignal.Dispose(); + detectedSignal = null; } } } @@ -128,7 +132,8 @@ namespace Tizen.NUI { if (_detectedCallback != null) { - DetectedSignal().Disconnect(_detectedCallback); + detectedSignal?.Disconnect(_detectedCallback); + detectedSignal?.Dispose(); } Interop.RotationGesture.DeleteRotationGestureDetector(swigCPtr); diff --git a/src/Tizen.NUI/src/public/Shader.cs b/src/Tizen.NUI/src/public/Shader.cs index 424f0f5..e970b57 100755 --- a/src/Tizen.NUI/src/public/Shader.cs +++ b/src/Tizen.NUI/src/public/Shader.cs @@ -59,12 +59,16 @@ namespace Tizen.NUI get { Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap(); - Tizen.NUI.Object.GetProperty(SwigCPtr, Shader.Property.PROGRAM).Get(temp); + var pValue = Tizen.NUI.Object.GetProperty(SwigCPtr, Shader.Property.PROGRAM); + pValue.Get(temp); + pValue.Dispose(); return temp; } set { - Tizen.NUI.Object.SetProperty(SwigCPtr, Shader.Property.PROGRAM, new Tizen.NUI.PropertyValue(value)); + var temp = new Tizen.NUI.PropertyValue(value); + Tizen.NUI.Object.SetProperty(SwigCPtr, Shader.Property.PROGRAM, temp); + temp.Dispose(); } } diff --git a/src/Tizen.NUI/src/public/StyleManager.cs b/src/Tizen.NUI/src/public/StyleManager.cs index b681815..75ed880 100755 --- a/src/Tizen.NUI/src/public/StyleManager.cs +++ b/src/Tizen.NUI/src/public/StyleManager.cs @@ -35,6 +35,7 @@ namespace Tizen.NUI private static readonly StyleManager instance = StyleManager.Get(); private EventHandler _styleManagerStyleChangedEventHandler; private StyleChangedCallbackDelegate _styleManagerStyleChangedCallbackDelegate; + private StyleChangedSignal styleChangedSignal; /// /// Creates a StyleManager handle.
@@ -63,16 +64,19 @@ namespace Tizen.NUI if (_styleManagerStyleChangedEventHandler == null) { _styleManagerStyleChangedCallbackDelegate = (OnStyleChanged); - StyleChangedSignal().Connect(_styleManagerStyleChangedCallbackDelegate); + styleChangedSignal = StyleChangedSignal(); + styleChangedSignal.Connect(_styleManagerStyleChangedCallbackDelegate); } _styleManagerStyleChangedEventHandler += value; } remove { _styleManagerStyleChangedEventHandler -= value; - if (_styleManagerStyleChangedEventHandler == null && StyleChangedSignal().Empty() == false) + if (_styleManagerStyleChangedEventHandler == null && styleChangedSignal?.Empty() == false) { - StyleChangedSignal().Disconnect(_styleManagerStyleChangedCallbackDelegate); + styleChangedSignal.Disconnect(_styleManagerStyleChangedCallbackDelegate); + styleChangedSignal.Dispose(); + styleChangedSignal = null; } } } diff --git a/src/Tizen.NUI/src/public/TTSPlayer.cs b/src/Tizen.NUI/src/public/TTSPlayer.cs index 30b874b..4baa611 100755 --- a/src/Tizen.NUI/src/public/TTSPlayer.cs +++ b/src/Tizen.NUI/src/public/TTSPlayer.cs @@ -29,6 +29,7 @@ namespace Tizen.NUI { private static readonly TTSPlayer instance = TTSPlayer.Get(); private StateChangedEventCallbackType _stateChangedEventCallback; + private StateChangedSignalType stateChangedSignal; internal TTSPlayer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.TtsPlayer.Upcast(cPtr), cMemoryOwn) { @@ -59,7 +60,8 @@ namespace Tizen.NUI if (_stateChangedEventHandler == null) { _stateChangedEventCallback = OnStateChanged; - StateChangedSignal().Connect(_stateChangedEventCallback); + stateChangedSignal = StateChangedSignal(); + stateChangedSignal.Connect(_stateChangedEventCallback); } _stateChangedEventHandler += value; @@ -68,9 +70,11 @@ namespace Tizen.NUI { _stateChangedEventHandler -= value; - if (_stateChangedEventHandler == null && StateChangedSignal().Empty() == false && _stateChangedEventCallback != null) + if (_stateChangedEventHandler == null && stateChangedSignal?.Empty() == false && _stateChangedEventCallback != null) { - StateChangedSignal().Disconnect(_stateChangedEventCallback); + stateChangedSignal.Disconnect(_stateChangedEventCallback); + stateChangedSignal.Dispose(); + stateChangedSignal = null; } } } diff --git a/src/Tizen.NUI/src/public/TapGestureDetector.cs b/src/Tizen.NUI/src/public/TapGestureDetector.cs index 9971fbd..25ef8a7 100755 --- a/src/Tizen.NUI/src/public/TapGestureDetector.cs +++ b/src/Tizen.NUI/src/public/TapGestureDetector.cs @@ -60,6 +60,7 @@ namespace Tizen.NUI [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void DetectedCallbackType(IntPtr actor, IntPtr TapGesture); private DetectedCallbackType _detectedCallback; + private TapGestureDetectedSignal detectedSignal; /// /// This signal is emitted when the specified tap is detected on the attached view. @@ -73,7 +74,8 @@ namespace Tizen.NUI if (_detectedEventHandler == null) { _detectedCallback = OnTapGestureDetected; - DetectedSignal().Connect(_detectedCallback); + detectedSignal = DetectedSignal(); + detectedSignal.Connect(_detectedCallback); } _detectedEventHandler += value; @@ -83,9 +85,11 @@ namespace Tizen.NUI { _detectedEventHandler -= value; - if (_detectedEventHandler == null && DetectedSignal().Empty() == false) + if (_detectedEventHandler == null && detectedSignal?.Empty() == false) { - DetectedSignal().Disconnect(_detectedCallback); + detectedSignal.Disconnect(_detectedCallback); + detectedSignal.Dispose(); + detectedSignal = null; } } } @@ -192,7 +196,8 @@ namespace Tizen.NUI { if (_detectedCallback != null) { - DetectedSignal().Disconnect(_detectedCallback); + detectedSignal?.Disconnect(_detectedCallback); + detectedSignal?.Dispose(); } Interop.TapGestureDetector.DeleteTapGestureDetector(swigCPtr); diff --git a/src/Tizen.NUI/src/public/Timer.cs b/src/Tizen.NUI/src/public/Timer.cs index df48769..75d00e2 100755 --- a/src/Tizen.NUI/src/public/Timer.cs +++ b/src/Tizen.NUI/src/public/Timer.cs @@ -38,7 +38,7 @@ namespace Tizen.NUI private bool played = false; private EventHandlerWithReturnType _timerTickEventHandler; private TickCallbackDelegate _timerTickCallbackDelegate; - + private TimerSignalType tickSignal; private System.IntPtr _timerTickCallbackOfNative; /// @@ -89,16 +89,19 @@ namespace Tizen.NUI { if (_timerTickEventHandler == null && disposed == false) { - TickSignal().Connect(_timerTickCallbackOfNative); + tickSignal = TickSignal(); + tickSignal.Connect(_timerTickCallbackOfNative); } _timerTickEventHandler += value; } remove { _timerTickEventHandler -= value; - if (_timerTickEventHandler == null && TickSignal().Empty() == false) + if (_timerTickEventHandler == null && tickSignal?.Empty() == false) { - TickSignal().Disconnect(_timerTickCallbackOfNative); + tickSignal.Disconnect(_timerTickCallbackOfNative); + tickSignal.Dispose(); + tickSignal = null; } } } @@ -270,7 +273,8 @@ namespace Tizen.NUI if (this != null && _timerTickCallbackDelegate != null) { - TickSignal().Disconnect(_timerTickCallbackOfNative); + tickSignal?.Disconnect(_timerTickCallbackOfNative); + tickSignal?.Dispose(); } if (disposed) diff --git a/src/Tizen.NUI/src/public/Utility/TextPageUtil.cs b/src/Tizen.NUI/src/public/Utility/TextPageUtil.cs index 7aa78b2..f410d55 100755 --- a/src/Tizen.NUI/src/public/Utility/TextPageUtil.cs +++ b/src/Tizen.NUI/src/public/Utility/TextPageUtil.cs @@ -131,7 +131,9 @@ namespace Tizen.NUI.Utility uint count = cutOffIndexArray.Count(); for (uint i = 0; i < count; i++) { - cutOffIndexArray.GetElementAt(i).Get(out cutOffIndex); // Gets the last index of text shown on the actual screen. + PropertyValue temp = cutOffIndexArray.GetElementAt(i); + temp.Get(out cutOffIndex); // Gets the last index of text shown on the actual screen. + temp.Dispose(); // If markup is enabled, It should parse markup if (label.EnableMarkup) -- 2.7.4