Files
sqltoolsservice/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/BufferRange.cs
Benjamin Russell 41198e9357 Adding sr.strings file and removing hard-coded strings (#52)
* Strings sweep for connection service

* String sweep for credentials service

* String sweep for hosting

* String sweep for query execution service

* String sweep for Workspace service

* Renaming utility namespace to match standards

Renaming Microsoft.SqlTools.EditorServices.Utility to
Microsoft.SqlTools.ServiceLayer.Utility to match the naming changes done a
while back. Also renaming them on the files that use them

* Namespace change on reliable connection

* Adding the new resx and designer files

* Final bug fixes for srgen

Fixing flakey moq package name

* Removing todo as per @kevcunnane

* Adding using statements as per @llali's comment

* Fixing issues from broken unit tests

Note: This feature contains changes that will break the contract for
saving as CSV and JSON. On success, null is returned as a message instead
of "Success". Changes will be made to the vscode component to handle this
change.
2016-09-16 16:18:25 -07:00

121 lines
3.7 KiB
C#

//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
using System.Diagnostics;
namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts
{
/// <summary>
/// Provides details about a range between two positions in
/// a file buffer.
/// </summary>
[DebuggerDisplay("Start = {Start.Line}:{Start.Column}, End = {End.Line}:{End.Column}")]
public class BufferRange
{
#region Properties
/// <summary>
/// Provides an instance that represents a range that has not been set.
/// </summary>
public static readonly BufferRange None = new BufferRange(0, 0, 0, 0);
/// <summary>
/// Gets the start position of the range in the buffer.
/// </summary>
public BufferPosition Start { get; private set; }
/// <summary>
/// Gets the end position of the range in the buffer.
/// </summary>
public BufferPosition End { get; private set; }
/// <summary>
/// Returns true if the current range is non-zero, i.e.
/// contains valid start and end positions.
/// </summary>
public bool HasRange
{
get
{
return this.Equals(BufferRange.None);
}
}
#endregion
#region Constructors
/// <summary>
/// Creates a new instance of the BufferRange class.
/// </summary>
/// <param name="start">The start position of the range.</param>
/// <param name="end">The end position of the range.</param>
public BufferRange(BufferPosition start, BufferPosition end)
{
if (start > end)
{
throw new ArgumentException(SR.WorkspaceServiceBufferPositionOutOfOrder(start.Line, start.Column,
end.Line, end.Column));
}
this.Start = start;
this.End = end;
}
/// <summary>
/// Creates a new instance of the BufferRange class.
/// </summary>
/// <param name="startLine">The 1-based starting line number of the range.</param>
/// <param name="startColumn">The 1-based starting column number of the range.</param>
/// <param name="endLine">The 1-based ending line number of the range.</param>
/// <param name="endColumn">The 1-based ending column number of the range.</param>
public BufferRange(
int startLine,
int startColumn,
int endLine,
int endColumn)
{
this.Start = new BufferPosition(startLine, startColumn);
this.End = new BufferPosition(endLine, endColumn);
}
#endregion
#region Public Methods
/// <summary>
/// Compares two instances of the BufferRange class.
/// </summary>
/// <param name="obj">The object to which this instance will be compared.</param>
/// <returns>True if the ranges are equal, false otherwise.</returns>
public override bool Equals(object obj)
{
if (!(obj is BufferRange))
{
return false;
}
BufferRange other = (BufferRange)obj;
return
this.Start.Equals(other.Start) &&
this.End.Equals(other.End);
}
/// <summary>
/// Calculates a unique hash code that represents this instance.
/// </summary>
/// <returns>A hash code representing this instance.</returns>
public override int GetHashCode()
{
return this.Start.GetHashCode() ^ this.End.GetHashCode();
}
#endregion
}
}