Search Results for

    Show / Hide Table of Contents

    Struct TextSpan

    Immutable abstract representation of a span of text. For example, in an error diagnostic that reports a location, it could come from a parsed string, text from a tool editor buffer, etc.

    Implements
    IEquatable<TextSpan>
    IComparable<TextSpan>
    Inherited Members
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetType()
    System.Object.ReferenceEquals(System.Object, System.Object)
    Namespace: Loretta.CodeAnalysis.Text
    Assembly: Loretta.CodeAnalysis.dll
    Syntax
    [DataContract]
    public readonly struct TextSpan

    Constructors

    | Improve this Doc View Source

    TextSpan(Int32, Int32)

    Creates a TextSpan instance beginning with the position Start and having the Length specified with length.

    Declaration
    public TextSpan(int start, int length)
    Parameters
    Type Name Description
    System.Int32 start
    System.Int32 length

    Properties

    | Improve this Doc View Source

    End

    End of the span.

    Declaration
    public readonly int End { get; }
    Property Value
    Type Description
    System.Int32
    | Improve this Doc View Source

    IsEmpty

    Determines whether or not the span is empty.

    Declaration
    public readonly bool IsEmpty { get; }
    Property Value
    Type Description
    System.Boolean
    | Improve this Doc View Source

    Length

    Length of the span.

    Declaration
    [DataMember(Order = 1)]
    public readonly int Length { get; }
    Property Value
    Type Description
    System.Int32
    | Improve this Doc View Source

    Start

    Start point of the span.

    Declaration
    [DataMember(Order = 0)]
    public readonly int Start { get; }
    Property Value
    Type Description
    System.Int32

    Methods

    | Improve this Doc View Source

    CompareTo(TextSpan)

    Compares current instance of TextSpan with another.

    Declaration
    public readonly int CompareTo(TextSpan other)
    Parameters
    Type Name Description
    TextSpan other
    Returns
    Type Description
    System.Int32
    | Improve this Doc View Source

    Contains(TextSpan)

    Determines whether span falls completely within this span.

    Declaration
    public readonly bool Contains(TextSpan span)
    Parameters
    Type Name Description
    TextSpan span

    The span to check.

    Returns
    Type Description
    System.Boolean

    true if the specified span falls completely within this span, otherwise false.

    | Improve this Doc View Source

    Contains(Int32)

    Determines whether the position lies within the span.

    Declaration
    public readonly bool Contains(int position)
    Parameters
    Type Name Description
    System.Int32 position

    The position to check.

    Returns
    Type Description
    System.Boolean

    true if the position is greater than or equal to Start and strictly less than End, otherwise false.

    | Improve this Doc View Source

    Equals(TextSpan)

    Determines if current instance of TextSpan is equal to another.

    Declaration
    public readonly bool Equals(TextSpan other)
    Parameters
    Type Name Description
    TextSpan other
    Returns
    Type Description
    System.Boolean
    | Improve this Doc View Source

    Equals(Object)

    Determines if current instance of TextSpan is equal to another.

    Declaration
    public override readonly bool Equals(object obj)
    Parameters
    Type Name Description
    System.Object obj
    Returns
    Type Description
    System.Boolean
    Overrides
    System.ValueType.Equals(System.Object)
    | Improve this Doc View Source

    FromBounds(Int32, Int32)

    Creates a new TextSpan from start and end positions as opposed to a position and length.

    The returned TextSpan contains the range with start inclusive, and end exclusive.

    Declaration
    public static TextSpan FromBounds(int start, int end)
    Parameters
    Type Name Description
    System.Int32 start
    System.Int32 end
    Returns
    Type Description
    TextSpan
    | Improve this Doc View Source

    GetHashCode()

    Produces a hash code for TextSpan.

    Declaration
    public override readonly int GetHashCode()
    Returns
    Type Description
    System.Int32
    Overrides
    System.ValueType.GetHashCode()
    | Improve this Doc View Source

    Intersection(TextSpan)

    Returns the intersection with the given span, or null if there is no intersection.

    Declaration
    public readonly TextSpan? Intersection(TextSpan span)
    Parameters
    Type Name Description
    TextSpan span

    The span to check.

    Returns
    Type Description
    System.Nullable<TextSpan>

    The intersection of the spans, or null if the intersection is empty.

    | Improve this Doc View Source

    IntersectsWith(TextSpan)

    Determines whether span intersects this span. Two spans are considered to intersect if they have positions in common or the end of one span coincides with the start of the other span.

    Declaration
    public readonly bool IntersectsWith(TextSpan span)
    Parameters
    Type Name Description
    TextSpan span

    The span to check.

    Returns
    Type Description
    System.Boolean

    true if the spans intersect, otherwise false.

    | Improve this Doc View Source

    IntersectsWith(Int32)

    Determines whether position intersects this span. A position is considered to intersect if it is between the start and end positions (inclusive) of this span.

    Declaration
    public readonly bool IntersectsWith(int position)
    Parameters
    Type Name Description
    System.Int32 position

    The position to check.

    Returns
    Type Description
    System.Boolean

    true if the position intersects, otherwise false.

    | Improve this Doc View Source

    Overlap(TextSpan)

    Returns the overlap with the given span, or null if there is no overlap.

    Declaration
    public readonly TextSpan? Overlap(TextSpan span)
    Parameters
    Type Name Description
    TextSpan span

    The span to check.

    Returns
    Type Description
    System.Nullable<TextSpan>

    The overlap of the spans, or null if the overlap is empty.

    | Improve this Doc View Source

    OverlapsWith(TextSpan)

    Determines whether span overlaps this span. Two spans are considered to overlap if they have positions in common and neither is empty. Empty spans do not overlap with any other span.

    Declaration
    public readonly bool OverlapsWith(TextSpan span)
    Parameters
    Type Name Description
    TextSpan span

    The span to check.

    Returns
    Type Description
    System.Boolean

    true if the spans overlap, otherwise false.

    | Improve this Doc View Source

    ToString()

    Provides a string representation for TextSpan.

    Declaration
    public override readonly string ToString()
    Returns
    Type Description
    System.String
    Overrides
    System.ValueType.ToString()

    Operators

    | Improve this Doc View Source

    Equality(TextSpan, TextSpan)

    Determines if two instances of TextSpan are the same.

    Declaration
    public static bool operator ==(TextSpan left, TextSpan right)
    Parameters
    Type Name Description
    TextSpan left
    TextSpan right
    Returns
    Type Description
    System.Boolean
    | Improve this Doc View Source

    Inequality(TextSpan, TextSpan)

    Determines if two instances of TextSpan are different.

    Declaration
    public static bool operator !=(TextSpan left, TextSpan right)
    Parameters
    Type Name Description
    TextSpan left
    TextSpan right
    Returns
    Type Description
    System.Boolean

    Implements

    IEquatable<>
    IComparable<>
    • Improve this Doc
    • View Source
    ☀
    ☾
    In This Article
    Back to top

    Copyright (c) LorettaDevs

    Generated by DocFX

    ☀
    ☾