Skip to content

Commit a78ef02

Browse files
Use pattern matching (#56532)
Use pattern matching to avoid casts.
1 parent c52c284 commit a78ef02

File tree

6 files changed

+7
-7
lines changed

6 files changed

+7
-7
lines changed

src/Http/Http.Abstractions/src/FragmentString.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public override bool Equals(object? obj)
128128
{
129129
return !HasValue;
130130
}
131-
return obj is FragmentString && Equals((FragmentString)obj);
131+
return obj is FragmentString value && Equals(value);
132132
}
133133

134134
/// <summary>

src/Http/Http.Abstractions/src/HostString.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ public override bool Equals(object? obj)
298298
{
299299
return !HasValue;
300300
}
301-
return obj is HostString && Equals((HostString)obj);
301+
return obj is HostString value && Equals(value);
302302
}
303303

304304
/// <summary>

src/Http/Http.Abstractions/src/Internal/HeaderSegment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public override bool Equals(object? obj)
4141
return false;
4242
}
4343

44-
return obj is HeaderSegment && Equals((HeaderSegment)obj);
44+
return obj is HeaderSegment value && Equals(value);
4545
}
4646

4747
public override int GetHashCode()

src/Http/Http.Abstractions/src/Internal/HeaderSegmentCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public override bool Equals(object? obj)
2727
return false;
2828
}
2929

30-
return obj is HeaderSegmentCollection && Equals((HeaderSegmentCollection)obj);
30+
return obj is HeaderSegmentCollection collection && Equals(collection);
3131
}
3232

3333
public override int GetHashCode()

src/Http/Http.Abstractions/src/QueryString.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public override bool Equals(object? obj)
231231
{
232232
return !HasValue;
233233
}
234-
return obj is QueryString && Equals((QueryString)obj);
234+
return obj is QueryString query && Equals(query);
235235
}
236236

237237
/// <summary>

src/Shared/RazorViews/BaseView.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ protected void WriteAttribute(
193193
// instead of the string 'true'. If the value is the bool 'false' we don't want to write anything.
194194
// Otherwise the value is another object (perhaps an HtmlString) and we'll ask it to format itself.
195195
string? stringValue;
196-
if (value.Value is bool)
196+
if (value.Value is bool flag)
197197
{
198-
if ((bool)value.Value)
198+
if (flag)
199199
{
200200
stringValue = name;
201201
}

0 commit comments

Comments
 (0)