Skip to content

Commit

Permalink
Use pattern matching (#56532)
Browse files Browse the repository at this point in the history
Use pattern matching to avoid casts.
  • Loading branch information
martincostello authored Jul 10, 2024
1 parent c52c284 commit a78ef02
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Http/Http.Abstractions/src/FragmentString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public override bool Equals(object? obj)
{
return !HasValue;
}
return obj is FragmentString && Equals((FragmentString)obj);
return obj is FragmentString value && Equals(value);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Http.Abstractions/src/HostString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public override bool Equals(object? obj)
{
return !HasValue;
}
return obj is HostString && Equals((HostString)obj);
return obj is HostString value && Equals(value);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Http.Abstractions/src/Internal/HeaderSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override bool Equals(object? obj)
return false;
}

return obj is HeaderSegment && Equals((HeaderSegment)obj);
return obj is HeaderSegment value && Equals(value);
}

public override int GetHashCode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public override bool Equals(object? obj)
return false;
}

return obj is HeaderSegmentCollection && Equals((HeaderSegmentCollection)obj);
return obj is HeaderSegmentCollection collection && Equals(collection);
}

public override int GetHashCode()
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Http.Abstractions/src/QueryString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public override bool Equals(object? obj)
{
return !HasValue;
}
return obj is QueryString && Equals((QueryString)obj);
return obj is QueryString query && Equals(query);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Shared/RazorViews/BaseView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ protected void WriteAttribute(
// instead of the string 'true'. If the value is the bool 'false' we don't want to write anything.
// Otherwise the value is another object (perhaps an HtmlString) and we'll ask it to format itself.
string? stringValue;
if (value.Value is bool)
if (value.Value is bool flag)
{
if ((bool)value.Value)
if (flag)
{
stringValue = name;
}
Expand Down

0 comments on commit a78ef02

Please sign in to comment.