本文整理汇总了C#中IFormatProvider.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# IFormatProvider.ToString方法的具体用法?C# IFormatProvider.ToString怎么用?C# IFormatProvider.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFormatProvider
的用法示例。
在下文中一共展示了IFormatProvider.ToString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FormatTypeConversionExceptionMesssage
/// <summary>
/// Formats the message for the TypeConversionException
/// </summary>
/// <param name="value">The value that the user tried to convert</param>
/// <param name="defaultValue">The default value used</param>
/// <param name="targetType">The target type</param>
/// <param name="format">The format provider</param>
/// <returns>A string containing the message for the generated TypeConversionException</returns>
public static string FormatTypeConversionExceptionMesssage(object value, object defaultValue, Type targetType, IFormatProvider format)
{
string valueTypeName = (value != null) ? value.GetType().ToString() : "(undefined type)";
string valueString = (value != null) ? (IsDBNull(value) ? "[NULL]" : value.ToString()) : "(null)";
string defaultValueTypeName = (defaultValue != null) ? defaultValue.GetType().ToString() : "(undefined type)";
string defaultValueString = (defaultValue != null) ? (IsDBNull(defaultValue) ? "[NULL]" : defaultValue.ToString()) : "(null)";
string targetTypeName = (targetType != null) ? targetType.ToString() : "(undefined type)";
string formatProviderTypeName = (format != null) ? format.GetType().ToString() : "(undefined type)";
string cultureName = (format != null) ? format.ToString() : string.Empty;
return string.Format(
"Error(s) occured while trying to convert value '{0}' (of type '{1}') to type '{2}' using default value '{3}' (of type '{4}') and format provider '{5}' (of type '{6}')",
valueString,
valueTypeName,
targetTypeName,
defaultValueString,
defaultValueString,
cultureName,
formatProviderTypeName);
}
示例2: GetDataString
private string GetDataString(string strSrc, IFormatProvider provider)
{
string str1, str2, str;
int len1;
if (null == strSrc)
{
str1 = "null";
len1 = 0;
}
else
{
str1 = strSrc;
len1 = strSrc.Length;
}
str2 = (null == provider) ? "null" : provider.ToString();
str = string.Format("\n[Source string value]\n \"{0}\"", str1);
str += string.Format("\n[Length of source string]\n {0}", len1);
str += string.Format("\n[Format provider string]\n {0}", str2);
return str;
}