本文整理汇总了C#中IFormatProvider.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# IFormatProvider.Equals方法的具体用法?C# IFormatProvider.Equals怎么用?C# IFormatProvider.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFormatProvider
的用法示例。
在下文中一共展示了IFormatProvider.Equals方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Format
public string Format(string format, object arg, IFormatProvider formatProvider)
{
var timeSpan = arg as TimeSpan?;
if (!formatProvider.Equals(this) || timeSpan == null)
return null;
var days = (int) Math.Floor(timeSpan.Value.TotalDays);
var hours = (int) Math.Floor((double) timeSpan.Value.Hours);
var minutes = (int) Math.Floor((double) timeSpan.Value.Minutes);
var seconds = (int) Math.Floor((double) timeSpan.Value.Seconds);
return format
.Replace("dd", days.ToString("00"))
.Replace("d", days.ToString())
.Replace("hh", hours.ToString("00"))
.Replace("h", hours.ToString())
.Replace("mm", minutes.ToString("00"))
.Replace("m", minutes.ToString())
.Replace("ss", seconds.ToString("00"))
.Replace("s", seconds.ToString());
}
示例2: Format
public string Format(string format, object arg,
IFormatProvider formatProvider)
{
if (!formatProvider.Equals(this)) return null;
// Handle only hexadecimal format string.
if (!format.StartsWith("X")) return null;
byte[] bytes;
string output = null;
// Handle only integral types.
if (arg is byte)
bytes = BitConverter.GetBytes((byte)arg);
else if (arg is Int16)
bytes = BitConverter.GetBytes((Int16)arg);
else if (arg is Int32)
bytes = BitConverter.GetBytes((Int32)arg);
else if (arg is Int64)
bytes = BitConverter.GetBytes((Int64)arg);
else if (arg is SByte)
bytes = BitConverter.GetBytes((SByte)arg);
else if (arg is UInt16)
bytes = BitConverter.GetBytes((UInt16)arg);
else if (arg is UInt32)
bytes = BitConverter.GetBytes((UInt32)arg);
else if (arg is UInt64)
bytes = BitConverter.GetBytes((UInt64)arg);
else if (arg is byte[])
bytes = (byte[])arg;
else
return null;
for (int ctr = bytes.Length - 1; ctr >= 0; ctr--)
output += String.Format("{0:X2} ", bytes[ctr]);
return output.Trim();
}
示例3: Format
public string Format(string format, object arg, IFormatProvider formatProvider)
{
try
{
if (!formatProvider.Equals(this)) return (null);
if (!format.StartsWith("MAC")) return (null);
if (arg is UInt64)
{
return (toString((UInt64)arg));
}
else
{
return (null);
}
}
catch
{
return (null);
}
}