我们正在寻找实施自定义格式化程序,按照惯例,最好使用来自Microsoft的接口,所以我找到了ICustomFormatter。IFormatProvider在ICustomFormatter
http://msdn.microsoft.com/en-us/library/system.icustomformatter.format(v=vs.110).aspx
但是该接口的签名来提供这种:
public string Format(string format, object arg, IFormatProvider formatProvider)
{
}
我甚至会使用formatProvider呢?我还没有看到好为什么你关心什么formatProvider加载了这个ICustomFormatter的例子。
我发现的唯一的例子是这样的:
http://www.codeproject.com/Articles/6533/Custom-String-Formatting-in-NET
if (formatProvider is NumberFormatInfo)
if (((NumberFormatInfo)formatProvider).UseDiacritic)
c = diacritic;
但这只是看起来像可怕的设计(需要一个接口,然后强耦合的话)。
我错过了一些特殊用例吗?
IFormatProvider是不是用于允许不同区域或文化中的相同类型的数据的不同格式?因此,例如,货币格式输出“$”表示en-us,“£”表示en-gb。 – acfrancis
这就是你需要知道的全部http://msdn.microsoft.com/en-us/library/system.iformatprovider.getformat%28v=vs.110%29.aspx –