本文整理汇总了C#中IFormatProvider.IsMonthFirst方法的典型用法代码示例。如果您正苦于以下问题:C# IFormatProvider.IsMonthFirst方法的具体用法?C# IFormatProvider.IsMonthFirst怎么用?C# IFormatProvider.IsMonthFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFormatProvider
的用法示例。
在下文中一共展示了IFormatProvider.IsMonthFirst方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPatterns
/// <summary>
/// Returns a set of regular expressions supported by this parser.
/// </summary>
/// <param name="provider">An <see cref="IFormatProvider"/>.</param>
/// <returns>A set of regular expressions supported by this parser.</returns>
public override IEnumerable<string> GetPatterns(IFormatProvider provider)
{
if (provider.IsMonthFirst())
{
return GetPatternsWithMonthFirst(provider);
}
else if (provider.IsYearFirst())
{
return GetPatternsWithYearFirst(provider);
}
else
{
return GetPatternsWithDayFirst(provider);
}
}
示例2: ToString
/// <summary>
/// Returns a string that represents the current object.
/// </summary>
/// <param name="provider">An <see cref="IFormatProvider"/> to use.</param>
/// <returns>A string that represents the current object.</returns>
public override string ToString(IFormatProvider provider)
{
try
{
this.ThrowIfNotValid();
// Day only
if (this.Day.HasValue && !this.Month.HasValue && !this.Year.HasValue)
{
return string.Format(
Resources.ResourceManager.GetEffectiveProvider(provider),
Resources.ResourceManager.GetString("NormalDateTokenDayOnlyFormatString", provider),
DateTimeExtensions.GetOrdinalDayString(this.Day.Value, provider));
}
// Day and month
if (this.Day.HasValue && this.Month.HasValue && !this.Year.HasValue)
{
string formatString = provider.IsMonthFirst()
? Resources.ResourceManager.GetString("NormalDateTokenMonthAndDayFormatString", provider)
: Resources.ResourceManager.GetString("NormalDateTokenDayAndMonthFormatString", provider);
return string.Format(
Resources.ResourceManager.GetEffectiveProvider(provider),
formatString,
this.Day.Value,
DateTimeExtensions.GetMonthString(this.Month.Value, provider));
}
// Day, month, and year
if (this.Day.HasValue && this.Month.HasValue && this.Year.HasValue)
{
string formatString = provider.IsMonthFirst()
? Resources.ResourceManager.GetString("NormalDateTokenMonthDayAndYearFormatString", provider)
: Resources.ResourceManager.GetString("NormalDateTokenDayMonthAndYearFormatString", provider);
return string.Format(
Resources.ResourceManager.GetEffectiveProvider(provider),
formatString,
this.Day.Value,
DateTimeExtensions.GetMonthString(this.Month.Value, provider),
this.Year.Value);
}
// Month only
if (!this.Day.HasValue && this.Month.HasValue && !this.Year.HasValue)
{
return string.Format(
Resources.ResourceManager.GetEffectiveProvider(provider),
Resources.ResourceManager.GetString("NormalDateTokenMonthOnlyFormatString", provider),
DateTimeExtensions.GetMonthString(this.Month.Value, provider));
}
// Month and year
if (!this.Day.HasValue && this.Month.HasValue && this.Year.HasValue)
{
return string.Format(
Resources.ResourceManager.GetEffectiveProvider(provider),
Resources.ResourceManager.GetString("NormalDateTokenMonthAndYearFormatString", provider),
DateTimeExtensions.GetMonthString(this.Month.Value, provider),
this.Year);
}
// Year
if (!this.Day.HasValue && !this.Month.HasValue && this.Year.HasValue)
{
return string.Format(
Resources.ResourceManager.GetEffectiveProvider(provider),
Resources.ResourceManager.GetString("NormalDateTokenYearOnlyFormatString", provider),
this.Year);
}
// Unsupported
return this.GetType().ToString();
}
catch
{
return this.GetType().ToString();
}
}