[NUI] Fix Svace issues of dereferenced nullable variables
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Thu, 6 Oct 2022 12:36:23 +0000 (21:36 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Wed, 12 Oct 2022 09:45:12 +0000 (18:45 +0900)
Svace issues of dereferenced nullable variables have been fixed.

src/Tizen.NUI.Components/Controls/AlertDialog.cs
src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.cs
src/Tizen.NUI.Components/Controls/Pagination.cs
src/Tizen.NUI.Wearable/src/public/RecyclerView/RecyclerView.cs
src/Tizen.NUI/src/internal/EXaml/Operation/GetStaticObject.cs
src/Tizen.NUI/src/internal/FrameBroker/DefaultFrameBroker.cs
src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs
src/Tizen.NUI/src/public/Common/Container.cs

index 5e98929..642bfaf 100755 (executable)
@@ -119,9 +119,9 @@ namespace Tizen.NUI.Components
             }
 
             // Apply ItemSpacing.
-            if ((alertDialogStyle.ItemSpacing != null) && Layout is LinearLayout)
+            if ((alertDialogStyle.ItemSpacing != null) && (Layout is LinearLayout linearLayout))
             {
-                (Layout as LinearLayout).CellPadding = new Size2D(alertDialogStyle.ItemSpacing.Width, alertDialogStyle.ItemSpacing.Height);
+                linearLayout.CellPadding = new Size2D(alertDialogStyle.ItemSpacing.Width, alertDialogStyle.ItemSpacing.Height);
             }
 
             // Apply Title style.
@@ -553,9 +553,9 @@ namespace Tizen.NUI.Components
                 VerticalAlignment = VerticalAlignment.Center,
             };
 
-            if (styleApplied && (alertDialogStyle != null) && (alertDialogStyle.ItemSpacing != null) && (Layout is LinearLayout))
+            if (styleApplied && (alertDialogStyle != null) && (alertDialogStyle.ItemSpacing != null) && (Layout is LinearLayout linearLayout))
             {
-                (Layout as LinearLayout).CellPadding = new Size2D(alertDialogStyle.ItemSpacing.Width, alertDialogStyle.ItemSpacing.Height);
+                linearLayout.CellPadding = new Size2D(alertDialogStyle.ItemSpacing.Width, alertDialogStyle.ItemSpacing.Height);
             }
 
             this.Relayout += OnRelayout;
index ca69f12..f22ffe0 100755 (executable)
@@ -67,9 +67,9 @@ namespace Tizen.NUI.Components
         public static readonly new BindableProperty PaddingProperty = BindableProperty.Create(nameof(Padding), typeof(Extents), typeof(FlexibleView), null, propertyChanged: (bindable, oldValue, newValue) =>
         {
             var instance = (FlexibleView)bindable;
-            if (newValue != null)
+            if (newValue is Extents extents)
             {
-                instance.InternalPadding = newValue as Extents;
+                instance.InternalPadding = extents;
             }
         },
         defaultValueCreator: (bindable) =>
index 5e6e78c..2618c5c 100755 (executable)
@@ -710,9 +710,9 @@ namespace Tizen.NUI.Components
                 return;
             }
 
-            if (container != null && container.Layout is LinearLayout)
+            if (container != null && (container.Layout is LinearLayout linearLayout))
             {
-                (container.Layout as LinearLayout).CellPadding = new Size2D(indicatorSpacing, 0);
+                linearLayout.CellPadding = new Size2D(indicatorSpacing, 0);
             }
 
             for (int i = 0; i < indicatorList.Count; i++)
index 606225e..611f334 100755 (executable)
@@ -264,8 +264,7 @@ namespace Tizen.NUI.Wearable
                 {
                     for (int i = 0; i < Children.Count; i++)
                     {
-                        RecycleItem item = Children[i] as RecycleItem;
-                        if (item.DataIndex == prevFocusedDataIndex)
+                        if ((Children[i] is RecycleItem item) && (item.DataIndex == prevFocusedDataIndex))
                         {
                             nextFocusedView = item;
                             break;
@@ -323,9 +322,9 @@ namespace Tizen.NUI.Wearable
                 }
 
                 focusedView = nextFocusedView;
-                if ((nextFocusedView as RecycleItem) != null)
+                if (nextFocusedView is RecycleItem item)
                 {
-                    prevFocusedDataIndex = (nextFocusedView as RecycleItem).DataIndex;
+                    prevFocusedDataIndex = item.DataIndex;
                 }
 
                 ScrollTo(targetPosition, true);
index 8e91623..788cde1 100755 (executable)
@@ -54,11 +54,11 @@ namespace Tizen.NUI.EXaml
 
                 if (null != fieldName)
                 {
-                    obj = type.GetField(fieldName, BindingFlags.Static | BindingFlags.Public).GetValue(null);
+                    obj = type.GetField(fieldName, BindingFlags.Static | BindingFlags.Public)?.GetValue(null);
                 }
                 else
                 {
-                    obj = type.GetProperty(propertyName, BindingFlags.Static | BindingFlags.Public).GetValue(null);
+                    obj = type.GetProperty(propertyName, BindingFlags.Static | BindingFlags.Public)?.GetValue(null);
                 }
             }
 
index d8314e1..90e04bf 100755 (executable)
@@ -141,7 +141,10 @@ namespace Tizen.NUI
 
         private void TransitionSetFinished(object sender, EventArgs e)
         {
-            (sender as TransitionSet).Finished -= TransitionSetFinished;
+            if (sender is TransitionSet transitionSet)
+            {
+                transitionSet.Finished -= TransitionSetFinished;
+            }
             providerImage.Unparent();
             providerImage.Dispose();
             providerImage = null;
index 2611584..1499912 100755 (executable)
@@ -2530,9 +2530,15 @@ namespace Tizen.NUI.BaseComponents
 
                 view.themeData?.selectorData?.BorderlineColor?.Reset(view);
 
-                Selector<Color> selector = newValue as Selector<Color>;
-                if (selector.HasAll()) view.SetBorderlineColor(selector.All);
-                else view.EnsureSelectorData().BorderlineColor = new TriggerableSelector<Color>(view, selector, view.SetBorderlineColor, true);
+                if (newValue is Selector<Color> selector)
+                {
+                    if (selector.HasAll()) view.SetBorderlineColor(selector.All);
+                    else view.EnsureSelectorData().BorderlineColor = new TriggerableSelector<Color>(view, selector, view.SetBorderlineColor, true);
+                }
+                else
+                {
+                    view.SetBorderlineColor((Color)newValue);
+                }
             },
             defaultValueCreator: (bindable) =>
             {
index a54c3af..da75095 100755 (executable)
@@ -201,9 +201,8 @@ namespace Tizen.NUI
 
                         if (null != parent)
                         {
-                            if (null != xNameToElements)
+                            if ((null != xNameToElements) && (xNameToElements[pair.Key] is View holdedXElements))
                             {
-                                var holdedXElements = xNameToElements[pair.Key] as View;
                                 holdedXElements.CopyBindingRelationShip(view);
                                 holdedXElements.CopyFrom(view);