Beispiel #1
0
        /// <summary>
        /// For a given Diagnostic, verifies its range and returns a *new* Diagnostic with updated line numbers.
        /// Throws an ArgumentNullException if the given Diagnostic is null.
        /// Throws an ArgumentException if the Range of the given Diagnostic is invalid.
        /// Throws and ArgumentOutOfRangeException if the updated line number is negative.
        /// </summary>
        public static Diagnostic WithUpdatedLineNumber(this Diagnostic diagnostic, int lineNrChange)
        {
            if (lineNrChange == 0)
            {
                return(diagnostic ?? throw new ArgumentNullException(nameof(diagnostic)));
            }
            var updatedRange = diagnostic.Range.WithUpdatedLineNumber(lineNrChange); // throws if the given diagnostic is null
            var updated      = diagnostic.Copy();

            updated.Range = updatedRange;
            return(updated);
        }
        /// <summary>
        /// Returns a copy of this diagnostic with the given offset added to the line numbers.
        /// </summary>
        /// <exception cref="ArgumentOutOfRangeException">
        /// The new diagnostic has negative line numbers.
        /// </exception>
        public static Diagnostic WithLineNumOffset(this Diagnostic diagnostic, int offset)
        {
            var copy = diagnostic.Copy();

            copy.Range.Start.Line += offset;
            copy.Range.End.Line   += offset;
            if (copy.Range.Start.Line < 0 || copy.Range.End.Line < 0)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(offset), "Translated diagnostic has negative line numbers.");
            }
            return(copy);
        }