Skip to content

Commit 048f67d

Browse files
committed
Respond to new code analysis warnings.
1 parent a56ab32 commit 048f67d

File tree

6 files changed

+14
-9
lines changed

6 files changed

+14
-9
lines changed

src/Caching/StackExchangeRedis/src/RedisCache.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,12 @@ private async Task RefreshAsync(IDatabase cache, string key, DateTimeOffset? abs
573573
{
574574
if (options.AbsoluteExpiration.HasValue && options.AbsoluteExpiration <= creationTime)
575575
{
576+
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
576577
throw new ArgumentOutOfRangeException(
577578
nameof(DistributedCacheEntryOptions.AbsoluteExpiration),
578579
options.AbsoluteExpiration.Value,
579580
"The absolute expiration value must be in the future.");
581+
#pragma warning restore CA2208 // Instantiate argument exceptions correctly
580582
}
581583

582584
if (options.AbsoluteExpirationRelativeToNow.HasValue)

src/Components/Components/src/Routing/TemplateSegment.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ public TemplateSegment(string template, string segment, bool isParameter)
2323
Value = segment[1..];
2424
}
2525

26-
var invalidCharacterIndex = Value.IndexOf('*');
27-
if (invalidCharacterIndex != -1)
26+
if (Value.Contains('*'))
2827
{
2928
throw new InvalidOperationException($"Invalid template '{template}'. A catch-all parameter may only have '*' or '**' at the beginning of the segment.");
3029
}
@@ -93,7 +92,7 @@ public TemplateSegment(string template, string segment, bool isParameter)
9392

9493
// Moving the check for this here instead of TemplateParser so we can allow catch-all.
9594
// We checked for '*' up above specifically for catch-all segments, this one checks for all others
96-
if (Value.IndexOf('*') != -1)
95+
if (Value.Contains('*'))
9796
{
9897
throw new InvalidOperationException($"Invalid template '{template}'. The character '*' in parameter segment '{{{segment}}}' is not allowed.");
9998
}

src/Http/Http/src/Internal/ResponseCookies.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,20 @@ public void Delete(string key, CookieOptions options)
122122
{
123123
rejectPredicate = (value, encKeyPlusEquals, opts) =>
124124
value.StartsWith(encKeyPlusEquals, StringComparison.OrdinalIgnoreCase) &&
125-
value.IndexOf($"domain={opts.Domain}", StringComparison.OrdinalIgnoreCase) != -1 &&
126-
value.IndexOf($"path={opts.Path}", StringComparison.OrdinalIgnoreCase) != -1;
125+
value.Contains($"domain={opts.Domain}", StringComparison.OrdinalIgnoreCase) &&
126+
value.Contains($"path={opts.Path}", StringComparison.OrdinalIgnoreCase);
127127
}
128128
else if (domainHasValue)
129129
{
130130
rejectPredicate = (value, encKeyPlusEquals, opts) =>
131131
value.StartsWith(encKeyPlusEquals, StringComparison.OrdinalIgnoreCase) &&
132-
value.IndexOf($"domain={opts.Domain}", StringComparison.OrdinalIgnoreCase) != -1;
132+
value.Contains($"domain={opts.Domain}", StringComparison.OrdinalIgnoreCase);
133133
}
134134
else if (pathHasValue)
135135
{
136136
rejectPredicate = (value, encKeyPlusEquals, opts) =>
137137
value.StartsWith(encKeyPlusEquals, StringComparison.OrdinalIgnoreCase) &&
138-
value.IndexOf($"path={opts.Path}", StringComparison.OrdinalIgnoreCase) != -1;
138+
value.Contains($"path={opts.Path}", StringComparison.OrdinalIgnoreCase);
139139
}
140140
else
141141
{

src/Http/Routing/src/Patterns/RoutePatternParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ private static bool IsValidLiteral(Context context, string literal)
441441
Debug.Assert(context != null);
442442
Debug.Assert(literal != null);
443443

444-
if (literal.IndexOf(QuestionMark) != -1)
444+
if (literal.Contains(QuestionMark))
445445
{
446446
context.Error = Resources.FormatTemplateRoute_InvalidLiteral(literal);
447447
return false;

src/Logging.AzureAppServices/src/BatchingLoggerProvider.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@ internal BatchingLoggerProvider(IOptionsMonitor<BatchingLoggerOptions> options)
3939
var loggerOptions = options.CurrentValue;
4040
if (loggerOptions.BatchSize <= 0)
4141
{
42+
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
4243
throw new ArgumentOutOfRangeException(nameof(loggerOptions.BatchSize), $"{nameof(loggerOptions.BatchSize)} must be a positive number.");
44+
#pragma warning restore CA2208 // Instantiate argument exceptions correctly
4345
}
4446
if (loggerOptions.FlushPeriod <= TimeSpan.Zero)
4547
{
48+
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
4649
throw new ArgumentOutOfRangeException(nameof(loggerOptions.FlushPeriod), $"{nameof(loggerOptions.FlushPeriod)} must be longer than zero.");
50+
#pragma warning restore CA2208 // Instantiate argument exceptions correctly
4751
}
4852

4953
_interval = loggerOptions.FlushPeriod;

src/Tools/Shared/CommandLine/CommandLineApplicationExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static CommandOption Option(this CommandLineApplication command, string t
2626
=> command.Option(
2727
template,
2828
description,
29-
template.IndexOf("<", StringComparison.Ordinal) != -1
29+
template.Contains('<')
3030
? template.EndsWith(">...", StringComparison.Ordinal) ? CommandOptionType.MultipleValue : CommandOptionType.SingleValue
3131
: CommandOptionType.NoValue);
3232

0 commit comments

Comments
 (0)