Skip to content

Commit d266337

Browse files
Fixed error caused by null-coalescing assignment operator (?=)
1 parent a5bad02 commit d266337

File tree

10 files changed

+35
-17
lines changed

10 files changed

+35
-17
lines changed

src/Controls/samples/Controls.Sample/Pages/HitTestingPage.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ private void HandleTapped(double x, double y)
138138
SelectionLabel.Text = "Selected: " + string.Join(" <- ", elements!.Select(x => x.GetType().Name));
139139
var e = elements!.FirstOrDefault() as Microsoft.Maui.Controls.View;
140140

141-
e?.BackgroundColor = new Microsoft.Maui.Graphics.Color(255, 0, 0);
141+
if (e != null)
142+
e.BackgroundColor = new Microsoft.Maui.Graphics.Color(255, 0, 0);
142143
}
143144

144145
// IWindowOverlayElement/IDrawable is implemented to show the rectangle selection lasso

src/Controls/src/Core/BindableLayout/BindableLayout.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ static void SetBindableLayoutController(BindableObject b, BindableLayoutControll
118118

119119
static void OnControllerChanged(BindableObject b, BindableLayoutController oldC, BindableLayoutController newC)
120120
{
121-
oldC?.ItemsSource = null;
121+
if (oldC != null)
122+
oldC.ItemsSource = null;
122123

123124
if (newC == null)
124125
{

src/Controls/src/Core/ImageElement.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ async static void CancelOldValue(ImageSource oldvalue)
137137
static void ImageSourceChanged(BindableObject bindable, ImageSource newSource)
138138
{
139139
var imageElement = (VisualElement)bindable;
140-
newSource?.Parent = imageElement;
140+
if (newSource != null)
141+
newSource.Parent = imageElement;
141142
imageElement?.InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
142143
}
143144

src/Controls/src/Core/Interactivity/TriggerBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ internal virtual void OnSeal()
9696
((SealedList<TriggerAction>)ExitActions).IsReadOnly = true;
9797
if (Setters != null)
9898
((SealedList<Setter>)Setters).IsReadOnly = true;
99-
Condition?.IsSealed = true;
99+
if (Condition != null)
100+
Condition.IsSealed = true;
100101
}
101102

102103
void OnConditionChanged(BindableObject bindable, bool oldValue, bool newValue)

src/Controls/src/Core/Internals/EffectUtilities.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ public static void RegisterEffectControlProvider(IEffectControlProvider self, IE
1515
controller.EffectControlProvider = null;
1616

1717
controller = newElement;
18-
controller?.EffectControlProvider = self;
18+
19+
if (controller != null)
20+
controller.EffectControlProvider = self;
1921
}
2022

2123
/// <include file="../../../docs/Microsoft.Maui.Controls.Internals/EffectUtilities.xml" path="//Member[@MemberName='UnregisterEffectControlProvider']/Docs/*" />

src/Controls/src/Core/ObservableWrapper.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,13 @@ public TRestrict this[int index]
144144
set
145145
{
146146
int innerIndex = ToInnerIndex(index);
147-
value?.Owned = true;
147+
if (value != null)
148+
value.Owned = true;
148149
TTrack old = _list[innerIndex];
149150
_list[innerIndex] = value;
150151

151-
old?.Owned = false;
152+
if (old != null)
153+
old.Owned = false;
152154
}
153155
}
154156

src/Controls/src/Core/SetterSpecificityList.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ public void SetValue(SetterSpecificity specificity, object value)
2424
if (_first is null || _first.Value.Key == specificity)
2525
{
2626
_first = new KeyValuePair<SetterSpecificity, object>(specificity, value);
27-
_values?[specificity] = value;
27+
if (_values != null)
28+
_values[specificity] = value;
2829
return;
2930
}
3031

3132
if (_second is null || _second.Value.Key == specificity)
3233
{
3334
_second = new KeyValuePair<SetterSpecificity, object>(specificity, value);
34-
_values?[specificity] = value;
35+
if (_values != null)
36+
_values[specificity] = value;
3537
return;
3638
}
3739

src/Controls/src/Core/StyleSheets/Selector.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ static void SetCurrentSelector(ref Selector root, ref Selector workingRoot, ref
116116
op.Left = workingRoot;
117117
op.Right = sel;
118118
workingRoot = op;
119-
workingRootParent?.Right = workingRoot;
119+
if (workingRootParent != null)
120+
workingRootParent.Right = workingRoot;
120121

121122
if (updateRoot)
122123
root = workingRoot;

src/Essentials/src/Accelerometer/AccelerometerQueue.shared.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ internal void Add(long timestamp, bool accelerating)
2525
added.IsAccelerating = accelerating;
2626
added.Next = null;
2727

28-
newest?.Next = added;
28+
if (newest != null)
29+
newest.Next = added;
2930

3031
newest = added;
3132

src/Graphics/src/Graphics.Skia/SkiaCanvasState.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,24 @@ public void SetBlur(float radius)
168168
_blurRadius = radius;
169169
_blurFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, _blurRadius);
170170

171-
_fillPaint?.MaskFilter = _blurFilter;
172-
_strokePaint?.MaskFilter = _blurFilter;
173-
_fontPaint?.MaskFilter = _blurFilter;
171+
if (_fillPaint != null)
172+
_fillPaint.MaskFilter = _blurFilter;
173+
if (_strokePaint != null)
174+
_strokePaint.MaskFilter = _blurFilter;
175+
if (_fontPaint != null)
176+
_fontPaint.MaskFilter = _blurFilter;
174177
}
175178
else
176179
{
177180
_isBlurred = false;
178181
_blurRadius = 0;
179182

180-
_fillPaint?.MaskFilter = null;
181-
_strokePaint?.MaskFilter = null;
182-
_fontPaint?.MaskFilter = null;
183+
if (_fillPaint != null)
184+
_fillPaint.MaskFilter = null;
185+
if (_strokePaint != null)
186+
_strokePaint.MaskFilter = null;
187+
if (_fontPaint != null)
188+
_fontPaint.MaskFilter = null;
183189
}
184190
}
185191
}

0 commit comments

Comments
 (0)