- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 61
 
Closed
Description
Version of the Meziantou.Analyzer NuGet package
2.0.243
Rule Identifier
MA0011
Target Framework
.NET 9.0
C# Language version
4.14.0-3.25412.6 (c167adef)
Description
MA0011 is currently reported when there's a method for which there's an overload taking a interpolated string and an overload taking both and IFormatProvider and an interpolated string, and that method is invoked with a fully culture-invariant interpolated string.
Reproduction Steps
Minimal code:
using System;
using System.Runtime.CompilerServices;
using Meziantou.Analyzer.Annotations;
internal sealed class Program
{
    private static void Main(string[] args)
    {
        Print($"{DateTime.Now:D}"); // MA0011 is reported. This is fine as the "D" format is culture-sensitive
        Print($"{new Bar():D}"); // MA0011 is reported. This is fine as the "D" format is culture-sensitive
        Print($"{new Bar():o} | {new Bar():D}"); // MA0011 is reported. This is fine as the "D" format is culture-sensitive
        Print($"{DateTime.Now:o}"); // MA0011 should not be reported as the "o" format is culture invariant
        Print($"{new Bar():o}"); // MA0011 should not be reported as the "o" format is culture invariant
        Print($"XXX"); // MA0011 should not be reported because ... :p
    }
    public static void Print(ref DefaultInterpolatedStringHandler interpolatedStringHandler)
    {
    }
    public static void Print(IFormatProvider provider, ref DefaultInterpolatedStringHandler interpolatedStringHandler)
    {
    }
}
[CultureInsensitiveType(format: "o")]
public sealed class Bar : IFormattable
{
    public string ToString(string? format, IFormatProvider? formatProvider)
    {
        return string.Empty;
    }
}Other information
No response
Copilot
Metadata
Metadata
Assignees
Labels
No labels