public CodeLocation(int index, int endIndex, int indexOnLine, int endIndexOnLine, int lineNumber, int endLineNumber) { Param.RequireGreaterThanOrEqualToZero(index, "index"); Param.RequireGreaterThanOrEqualTo(endIndex, index, "endIndex"); Param.RequireGreaterThanOrEqualToZero(indexOnLine, "indexOnLine"); Param.RequireGreaterThanOrEqualToZero(endIndexOnLine, "endIndexOnLine"); Param.RequireGreaterThanZero(lineNumber, "lineNumber"); Param.RequireGreaterThanOrEqualTo(endLineNumber, lineNumber, "endLineNumber"); #if DEBUG // If the entire segment is on the same line, make sure the end index is greater or equal to the start index. if (lineNumber == endLineNumber) { CsLanguageService.Debug.Assert( endIndexOnLine >= indexOnLine, "The end index must be greater than the start index, since they are both on the same line."); } #endif this.startPoint = new CodePoint(index, indexOnLine, lineNumber); this.endPoint = new CodePoint(endIndex, endIndexOnLine, endLineNumber); }
/// <summary> /// Joins the two given points. /// </summary> /// <param name="point1">The first point to join.</param> /// <param name="point2">The second point to join.</param> /// <returns>Returns the joined <see cref="CodePoint"/>.</returns> public static CodePoint Join(CodePoint point1, CodePoint point2) { Param.RequireNotNull(point1, "point1"); Param.RequireNotNull(point2, "point2"); if (point1 == null) { return(point2); } else if (point2 == null) { return(point1); } else { // Figure out which IndexOnLine to use. int indexOnLine; if (point1.LineNumber == point2.LineNumber) { indexOnLine = Math.Min(point1.IndexOnLine, point2.IndexOnLine); } else if (point1.LineNumber < point2.LineNumber) { indexOnLine = point1.IndexOnLine; } else { indexOnLine = point2.IndexOnLine; } return(new CodePoint( Math.Min(point1.Index, point2.Index), indexOnLine, Math.Min(point1.LineNumber, point2.LineNumber))); } }
/// <summary> /// Initializes a new instance of the CodeLocation class. /// </summary> public CodeLocation() { this.startPoint = new CodePoint(); this.endPoint = new CodePoint(); }
/// <summary> /// Joins the two given points. /// </summary> /// <param name="point1">The first point to join.</param> /// <param name="point2">The second point to join.</param> /// <returns>Returns the joined <see cref="CodePoint"/>.</returns> public static CodePoint Join(CodePoint point1, CodePoint point2) { Param.RequireNotNull(point1, "point1"); Param.RequireNotNull(point2, "point2"); if (point1 == null) { return point2; } else if (point2 == null) { return point1; } else { // Figure out which IndexOnLine to use. int indexOnLine; if (point1.LineNumber == point2.LineNumber) { indexOnLine = Math.Min(point1.IndexOnLine, point2.IndexOnLine); } else if (point1.LineNumber < point2.LineNumber) { indexOnLine = point1.IndexOnLine; } else { indexOnLine = point2.IndexOnLine; } return new CodePoint( Math.Min(point1.Index, point2.Index), indexOnLine, Math.Min(point1.LineNumber, point2.LineNumber)); } }