Skip to content

Commit b83608d

Browse files
committed
Added FormatProviderDefaults, a simplified approach to select the default IFormatProvider when not specified
1 parent 413dd5f commit b83608d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+

2+
using System;
3+
using System.Globalization;
4+
5+
namespace IGLib;
6+
7+
public static class FormatProviderDefaults
8+
{
9+
public static IFormatProvider Global { get; private set; } = CultureInfo.InvariantCulture;
10+
11+
public static void SetGlobal(IFormatProvider formatProvider)
12+
{
13+
if (formatProvider == null)
14+
throw new ArgumentNullException(nameof(formatProvider));
15+
16+
Global = formatProvider;
17+
}
18+
19+
public static IFormatProvider Resolve(IFormatProvider? specifiedFormatProvider)
20+
=> specifiedFormatProvider ?? Global;
21+
}
22+

0 commit comments

Comments
 (0)