Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ private static void AnalyzeInvocation(OperationAnalysisContext context, IMethodS
if (interpolatedStringArgument is IInterpolatedStringHandlerCreationOperation handlerCreation)
{
var interpolatedStringContent = handlerCreation.Content;
if (!cultureSensitiveContext.IsCultureSensitiveOperation(interpolatedStringContent, CultureSensitiveOptions.None))
// Use UnwrapNullableOfT to check the underlying type of nullable types
if (!cultureSensitiveContext.IsCultureSensitiveOperation(interpolatedStringContent, CultureSensitiveOptions.UnwrapNullableOfT))
{
context.ReportDiagnostic(Rule, operation);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,52 @@ await CreateProjectBuilder()
.ValidateAsync();
}

[Fact]
public async Task StringCreateWithInvariantCulture_WithNullableInteger_NoDiagnostic()
{
const string SourceCode = """
using System;
using System.Globalization;

class TypeName
{
public void Test()
{
int? n = 42;
var s = string.Create(CultureInfo.InvariantCulture, $"/v{n}");
}
}
""";
await CreateProjectBuilder()
.WithLanguageVersion(Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp10)
.WithTargetFramework(TargetFramework.Net6_0)
.WithSourceCode(SourceCode)
.ValidateAsync();
}

[Fact]
public async Task StringCreateWithInvariantCulture_WithNullableDouble_NoDiagnostic()
{
const string SourceCode = """
using System;
using System.Globalization;

class TypeName
{
public void Test()
{
double? value = 3.14;
var s = string.Create(CultureInfo.InvariantCulture, $"Value: {value}");
}
}
""";
await CreateProjectBuilder()
.WithLanguageVersion(Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp10)
.WithTargetFramework(TargetFramework.Net6_0)
.WithSourceCode(SourceCode)
.ValidateAsync();
}

[Fact]
public async Task StringCreateWithInvariantCulture_EmptyString_ShouldReport()
{
Expand Down