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


C# ParseContext.IsValid方法代码示例

本文整理汇总了C#中ParseContext.IsValid方法的典型用法代码示例。如果您正苦于以下问题:C# ParseContext.IsValid方法的具体用法?C# ParseContext.IsValid怎么用?C# ParseContext.IsValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ParseContext的用法示例。


在下文中一共展示了ParseContext.IsValid方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ParseDateTime


//.........这里部分代码省略.........
                if ( bTimePart )
                {
                    // a 'T' must follow
                    if ( !context.CheckAndAdvance( 'T') ) return false;
                }
            }

            if ( bTimePart )
            {
                // check format here

                // hour from 0 to 2
                if ( !context.ReadDigitAndAdvance( ref hour, 10, 2 ) ) return false;
                if ( !context.ReadDigitAndAdvance( ref hour, 1, hour < 20 ? 9 : 4 ) ) return false;
                if ( !context.CheckAndAdvance( ':' ) ) return false;
                int maxFirstDigit = hour == 24 ? 0 : 5;
                int maxSecondDigit = hour == 24 ? 0 : 9;
                if ( !context.ReadDigitAndAdvance( ref minute, 10, maxFirstDigit ) ) return false;
                if ( !context.ReadDigitAndAdvance( ref minute, 1, maxSecondDigit ) ) return false;
                if ( !context.CheckAndAdvance( ':' ) ) return false;
                int secondInt = 0;
                if ( !context.ReadDigitAndAdvance( ref secondInt, 10, maxFirstDigit ) ) return false;
                if ( !context.ReadDigitAndAdvance( ref secondInt, 1, maxSecondDigit ) ) return false;

                second = secondInt;

                if ( context.CheckAndAdvance( '.' ) )
                {
                    // fraction. do whatever seems fit.
                    int val = 0;
                    int digits = 0;
                    while ( context.ReadDigitAndAdvance( ref val, 1, 9) )
                    {
                        val *= 10;
                        digits += 1;
                        if ( digits >= 8 ) // precision loss - ignore
                            break;
                    }

                    if ( digits == 0 )
                        return false;

                    second += val * Math.Pow( 10.0, -digits - 1 );

                    // skip any further digits.
                    while ( context.ReadDigitAndAdvance( ref val, 0, 9) )
                        ;
                }
            }

            // timezone
            if ( context.CheckAndAdvance('Z') )
            {
                // timezone specified, it is UTC.
                eTZ = ETZ.UTC;
                offsetTZ = 0;
            }
            else if ( context.Check('+') || context.Check('-' ) )
            {
                // timezone offset, in hour:minute format
                bool bNegative = context.Check('-');
                context.Advance();

                // do not check the hour part, for those who are obscure.
                int temp = 0;
                if ( !context.ReadDigitAndAdvance( ref temp, 600, 9 ) ) return false;
                if ( !context.ReadDigitAndAdvance( ref temp, 60, 9 ) ) return false;
                if ( !context.CheckAndAdvance( ':' ) ) return false;
                if ( !context.ReadDigitAndAdvance( ref temp, 10, 5 ) ) return false;
                if ( !context.ReadDigitAndAdvance( ref temp, 1, 9 ) ) return false;

                eTZ = ETZ.Offset;
                offsetTZ = bNegative ? -temp : temp;
            }

            if ( context.IsValid() )
                return false;

            // C# specific
            if (year <= 0) year = 1;
            if (month == 0) month = 1;
            bool badjust = false;
            if (hour == 24)
            {
                hour = 0;
                badjust = true;
            }
            if (day == 0) day = 1;
            try {
                myValue = new System.DateTime(year, month, day, hour, minute, (int)second,
                    (int)(second * 1000) % 1000);
                if (badjust)
                    myValue.AddDays(1);
            }
            catch
            {
                return false;
            }
            return true;
        }
开发者ID:paladin74,项目名称:Dapple,代码行数:101,代码来源:SchemaTypes.cs


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