Пример #1
0
        /// <summary>
        /// Initializes a new instance of <see cref="PgnErrorInfo"/>.
        /// </summary>
        /// <param name="errorCode">
        /// The error code.
        /// </param>
        /// <param name="start">
        /// The start position of the text span where the error occurred.
        /// </param>
        /// <param name="length">
        /// The length of the text span where the error occurred.
        /// </param>
        /// <param name="parameters">
        /// Parameters of the error.
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Either <paramref name="start"/> or <paramref name="length"/>, or both are negative.
        /// </exception>
        public PgnErrorInfo(PgnErrorCode errorCode, int start, int length, string[] parameters)
        {
            if (start < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(start));
            }
            if (length < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(length));
            }

            ErrorCode  = errorCode;
            ErrorLevel = GetErrorLevel(errorCode);
            Start      = start;
            Length     = length;
            Parameters = parameters;
        }
Пример #2
0
        private static PgnErrorLevel GetErrorLevel(PgnErrorCode errorCode)
        {
            switch (errorCode)
            {
            case PgnErrorCode.IllegalCharacter:
            case PgnErrorCode.UnterminatedTagValue:
            case PgnErrorCode.UnrecognizedEscapeSequence:
            case PgnErrorCode.IllegalControlCharacterInTagValue:
            case PgnErrorCode.UnrecognizedMove:
            case PgnErrorCode.EmptyTag:
            case PgnErrorCode.MissingTagBracketOpen:
            case PgnErrorCode.MissingTagName:
            case PgnErrorCode.MissingTagValue:
            case PgnErrorCode.MultipleTagValues:
            case PgnErrorCode.MissingTagBracketClose:
            case PgnErrorCode.MissingMove:
            case PgnErrorCode.OrphanParenthesisClose:
            case PgnErrorCode.OrphanBracketOpen:
            case PgnErrorCode.OrphanTagValue:
            case PgnErrorCode.OrphanBracketClose:
            case PgnErrorCode.MissingParenthesisClose:
                return(PgnErrorLevel.Error);

            case PgnErrorCode.UnterminatedMultiLineComment:
            case PgnErrorCode.EmptyVariation:
            case PgnErrorCode.MissingTagSection:
            case PgnErrorCode.MissingGameTerminationMarker:
                return(PgnErrorLevel.Warning);

            case PgnErrorCode.EmptyNag:
            case PgnErrorCode.OverflowNag:
            case PgnErrorCode.MissingMoveNumber:
            case PgnErrorCode.OrphanPeriod:
            case PgnErrorCode.VariationBeforeNAG:
                return(PgnErrorLevel.Message);

            default:
                // Treat unknown error codes as just messages.
                return(PgnErrorLevel.Message);
            }
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of <see cref="PgnErrorInfo"/>.
 /// </summary>
 /// <param name="errorCode">
 /// The error code.
 /// </param>
 /// <param name="start">
 /// The start position of the text span where the error occurred.
 /// </param>
 /// <param name="length">
 /// The length of the text span where the error occurred.
 /// </param>
 /// <exception cref="ArgumentOutOfRangeException">
 /// Either <paramref name="start"/> or <paramref name="length"/>, or both are negative.
 /// </exception>
 public PgnErrorInfo(PgnErrorCode errorCode, int start, int length)
     : this(errorCode, start, length, null)
 {
 }
 public static LocalizedStringKey GetLocalizedStringKey(PgnErrorCode pgnErrorCode)
 => new LocalizedStringKey($"PgnError{pgnErrorCode}");