コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PatternDefinition"/> class.
 /// </summary>
 /// <param name="dateTokenParser">The <see cref="DateToken.Parser"/> for the date token part of the
 /// pattern.</param>
 /// <param name="timeTokenParser">The <see cref="TimeToken.Parser"/> for the time token part of the
 /// pattern.</param>
 /// <param name="pattern">The regular expression that matches a <see cref="DateTimeToken"/>.</param>
 public PatternDefinition(DateToken.Parser dateTokenParser, TimeToken.Parser timeTokenParser, string pattern)
 {
     this.DateTokenParser = dateTokenParser;
     this.TimeTokenParser = timeTokenParser;
     this.Pattern         = pattern;
 }
コード例 #2
0
 /// <summary>
 /// Returns a value indicating whether this parser can be used in conjunction with a specified <see
 /// cref="TimeToken.Parser"/>.
 /// </summary>
 /// <param name="timeTokenParser">A <see cref="TimeToken.Parser"/>.</param>
 /// <returns>A value indicating whether this parser can be used in conjunction with the specified <see
 /// cref="TimeToken.Parser"/>.</returns>
 public virtual bool IsCompatibleWith(TimeToken.Parser timeTokenParser)
 {
     return(true);
 }
コード例 #3
0
            /// <summary>
            /// Returns a list of <see cref="PatternDefinition"/> objects representing the patterns supported by the
            /// combination of the specified <see cref="DateToken.Parser"/> and <see cref="TimeToken.Parser"/>.
            /// </summary>
            /// <param name="dateTokenParser">A <see cref="DateToken.Parser"/>.</param>
            /// <param name="timeTokenParser">A <see cref="TimeToken.Parser"/>.</param>
            /// <param name="provider">The <see cref="IFormatProvider"/> that will be used when parsing.</param>
            /// <returns>A list of <see cref="PatternDefinition"/> objects.</returns>
            private static List <PatternDefinition> GetDateTimePatternDefinitions(DateToken.Parser dateTokenParser, TimeToken.Parser timeTokenParser, IFormatProvider provider)
            {
                if (!dateTokenParser.IsCompatibleWith(timeTokenParser) || !timeTokenParser.IsCompatibleWith(dateTokenParser))
                {
                    return(new List <PatternDefinition>());
                }

                List <PatternDefinition> list = new List <PatternDefinition>();

                foreach (string datePartPattern in dateTokenParser.GetPatterns(provider))
                {
                    foreach (string timePartPattern in timeTokenParser.GetPatterns(provider))
                    {
                        string dateTimePattern = GetDateTimePattern(datePartPattern, timePartPattern, provider);
                        list.Add(new PatternDefinition(dateTokenParser, timeTokenParser, dateTimePattern));

                        string timeDatePattern = GetTimeDatePattern(timePartPattern, datePartPattern, provider);
                        list.Add(new PatternDefinition(dateTokenParser, timeTokenParser, timeDatePattern));
                    }
                }

                return(list);
            }
コード例 #4
0
ファイル: EmptyDateToken.cs プロジェクト: zzj0402/hourglass
 /// <summary>
 /// Returns a value indicating whether this parser can be used in conjunction with a specified <see
 /// cref="TimeToken.Parser"/>.
 /// </summary>
 /// <param name="timeTokenParser">A <see cref="TimeToken.Parser"/>.</param>
 /// <returns>A value indicating whether this parser can be used in conjunction with the specified <see
 /// cref="TimeToken.Parser"/>.</returns>
 public override bool IsCompatibleWith(TimeToken.Parser timeTokenParser)
 {
     return(!(timeTokenParser is EmptyTimeToken.Parser));
 }