CK.Text.StringMatcher.SetError C# (CSharp) Method

SetError() public method

Sets an error and always returns false. The message starts with the caller's method name. Use SetSuccess to clear any existing error.
public SetError ( object expectedMessage = null, [ callerName = null ) : bool
expectedMessage object /// Optional object. Its will be used to generate an "expected '...'" message. ///
callerName [ Name of the caller (automatically injected by the compiler).
return bool
        public bool SetError( object expectedMessage = null, [CallerMemberName]string callerName = null )
        {
            _errorDescription = FormatMessage( expectedMessage, callerName );
            return false;
        }

Usage Example

        /// <summary>
        /// Matches Int32 values that must not start with '0' ('0' is valid but '0d', where d is any digit, is not).
        /// A signed integer starts with a '-'. '-0' is valid but '-0d' (where d is any digit) is not.
        /// If the value is to big for an Int32, it fails.
        /// </summary>
        /// <param name="this">This <see cref="StringMatcher"/>.</param>
        /// <param name="i">The result integer. 0 on failure.</param>
        /// <param name="minValue">Optional minimal value.</param>
        /// <param name="maxValue">Optional maximal value.</param>
        /// <returns><c>true</c> when matched, <c>false</c> otherwise.</returns>
        public static bool MatchInt32(this StringMatcher @this, out int i, int minValue = int.MinValue, int maxValue = int.MaxValue)
        {
            i = 0;
            int  savedIndex = @this.StartIndex;
            long value      = 0;
            bool signed;

            if (@this.IsEnd)
            {
                return(@this.SetError());
            }
            if ((signed = @this.TryMatchChar('-')) && @this.IsEnd)
            {
                return(@this.BackwardAddError(savedIndex));
            }

            char c;

            if (@this.TryMatchChar('0'))
            {
                if ([email protected] && (c = @this.Head) >= '0' && c <= '9')
                {
                    return(@this.BackwardAddError(savedIndex, "0...9"));
                }
                return(@this.SetSuccess());
            }
            unchecked
            {
                long iMax = Int32.MaxValue;
                if (signed)
                {
                    iMax = iMax + 1;
                }
                while ([email protected] && (c = @this.Head) >= '0' && c <= '9')
                {
                    value = value * 10 + (c - '0');
                    if (value > iMax)
                    {
                        break;
                    }
                    @this.UncheckedMove(1);
                }
            }
            if (@this.StartIndex > savedIndex)
            {
                if (signed)
                {
                    value = -value;
                }
                if (value < (long)minValue || value > (long)maxValue)
                {
                    return(@this.BackwardAddError(savedIndex, String.Format(CultureInfo.InvariantCulture, "value between {0} and {1}", minValue, maxValue)));
                }
                i = (int)value;
                return(@this.SetSuccess());
            }
            return(@this.SetError());
        }
All Usage Examples Of CK.Text.StringMatcher::SetError