[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 5e98929c78bf9edd9e0ffe7c462a92752817262d..642bfaf637073e9f45affa82242e237ae8cb07d1 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 ca69f12af6d1c712216a8a40e1b8bcaaf2006db0..f22ffe0b93f9795a8f1fc85d3697f948cf57ca2f 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 5e6e78c439ffebbed1f2cf02470844aad2d0fdc0..2618c5cbc148981ed4fb4dc59b7bfc199cfa5566 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 606225edee83d91e7c2d801c5a23a80c9c3b3b50..611f334d52fb96058ff53f6b2419bd86f7bb5bf9 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 8e91623f1d2d7724a2b39b39f022e9705d830c63..788cde137f06deb3ffaa8fdcaa311df29065e8e5 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 d8314e1a44649f6cfaa9c41a96e1661d417b7d0e..90e04bf18889c8f3d3b745df6ae86762fb584d16 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 26115841f03855b9ce83854b71057279bc197bc7..1499912a8645917ed07a5e3c96a17e11e7b28fdf 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 a54c3afa464bd3c100a2b1e077ec5474b63ca1f9..da750959c77a05c2229f3c139372397c4e09d716 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);