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
# Exclude ToString methods from analysis
MA0011.exclude_tostring_methods=true
# Report Nullable<T>.ToString when T is culture-sensitive
MA0011.consider_nullable_types=true