当前位置: 首页>>代码示例>>C#>>正文


C# IFormatProvider.IsMonthFirst方法代码示例

本文整理汇总了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);
     }
 }
开发者ID:ZhuXiaomin,项目名称:Hourglass,代码行数:20,代码来源:NormalDateToken.cs

示例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();
            }
        }
开发者ID:ZhuXiaomin,项目名称:Hourglass,代码行数:85,代码来源:NormalDateToken.cs


注:本文中的IFormatProvider.IsMonthFirst方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。