Skip to content

Commit 94a7f57

Browse files
committed
Skipped some redundant property accesses
1 parent 57b7d52 commit 94a7f57

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

Microsoft.Toolkit.Uwp.UI/Extensions/FrameworkElement/FrameworkElementExtensions.LogicalTree.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -153,44 +153,44 @@ public static partial class FrameworkElementExtensions
153153
}
154154
else if (element is ContentControl contentControl)
155155
{
156-
if (contentControl.Content is T result && predicate.Match(result))
157-
{
158-
return result;
159-
}
160-
161156
if (contentControl.Content is FrameworkElement content)
162157
{
158+
if (content is T result && predicate.Match(result))
159+
{
160+
return result;
161+
}
162+
163163
element = content;
164164

165165
goto Start;
166166
}
167167
}
168168
else if (element is Border border)
169169
{
170-
if (border.Child is T result && predicate.Match(result))
171-
{
172-
return result;
173-
}
174-
175170
if (border.Child is FrameworkElement child)
176171
{
172+
if (child is T result && predicate.Match(result))
173+
{
174+
return result;
175+
}
176+
177177
element = child;
178178

179179
goto Start;
180180
}
181181
}
182182
else if (element is ContentPresenter contentPresenter)
183183
{
184-
// Sometimes ContentPresenters are used in control templates instead of ContentControls
185-
// Therefore we should still check if it's Content is a FrameworkElement and match.
184+
// Sometimes ContentPresenter is used in control templates instead of ContentControl,
185+
// therefore we should still check if its Content is a matching FrameworkElement instance.
186186
// This also makes this work for SwitchPresenter.
187-
if (contentPresenter.Content is T result && predicate.Match(result))
188-
{
189-
return result;
190-
}
191-
192187
if (contentPresenter.Content is FrameworkElement content)
193188
{
189+
if (content is T result && predicate.Match(result))
190+
{
191+
return result;
192+
}
193+
194194
element = content;
195195

196196
goto Start;
@@ -200,13 +200,13 @@ public static partial class FrameworkElementExtensions
200200
{
201201
// We put UserControl right before the slower reflection fallback path as
202202
// this type is less likely to be used compared to the other ones above.
203-
if (userControl.Content is T result && predicate.Match(result))
204-
{
205-
return result;
206-
}
207-
208203
if (userControl.Content is FrameworkElement content)
209204
{
205+
if (content is T result && predicate.Match(result))
206+
{
207+
return result;
208+
}
209+
210210
element = content;
211211

212212
goto Start;

0 commit comments

Comments
 (0)