Skip to content

Latest commit

 

History

History
37 lines (26 loc) · 1.07 KB

MA0011.md

File metadata and controls

37 lines (26 loc) · 1.07 KB

MA0011 - IFormatProvider is missing

This rule warns about the usage of overloads of methods like Parse, TryParse and ToString that do not take a parameter of type IFormatProvider.

More information on Creating Globally Aware Applications here: Creating Globally Aware Applications

DateTime.TryParse("", out var result);

// Should be
DateTime.TryParse("", CultureInfo.InvariantCulture, DateTimeStyles.None, out var result);
DateTime dt;

dt.ToString();    // non-compliant
dt.ToString("o"); // ok as "o" is a culture invariant format
DateTime? dt;

dt.ToString(); // non-compliant
dt?.ToString(CultureInfo.CurrentCulture); // ok
dt?.ToString("o"); // ok as "o" is a culture invariant format

Configuration

# Exclude ToString methods from analysis
MA0011.exclude_tostring_methods=true

# Report Nullable<T>.ToString when T is culture-sensitive
MA0011.consider_nullable_types=true