Fork me on GitHub
  • API

    Class MemoryExtensions

    Extensions to System.Memory types, such as Span<T> and ReadOnlySpan<T>.

    Inheritance
    object
    MemoryExtensions
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Lucene.Net
    Assembly: Lucene.Net.dll
    Syntax
    public static class MemoryExtensions

    Methods

    AsMemory(ICharTermAttribute)

    Creates a new ReadOnlyMemory<T> over the portion of the target string.

    Declaration
    public static ReadOnlyMemory<char> AsMemory(this ICharTermAttribute text)
    Parameters
    Type Name Description
    ICharTermAttribute text

    The target string.

    Returns
    Type Description
    ReadOnlyMemory<char>

    The read-only character memory representation of the string, or default if text is null.

    Remarks

    Returns default when text is null.

    AsMemory(ICharTermAttribute, Index)

    Creates a new ReadOnlyMemory<T> over the portion of the target string.

    Declaration
    public static ReadOnlyMemory<char> AsMemory(this ICharTermAttribute text, Index startIndex)
    Parameters
    Type Name Description
    ICharTermAttribute text

    The target string.

    Index startIndex

    The index at which to begin this slice.

    Returns
    Type Description
    ReadOnlyMemory<char>

    The read-only character memory representation of the string.

    Exceptions
    Type Condition
    ArgumentNullException

    text is null.

    ArgumentOutOfRangeException

    startIndex is less than 0 or greater than text.Length.

    AsMemory(ICharTermAttribute, int)

    Creates a new ReadOnlyMemory<T> over the portion of the target string.

    Declaration
    public static ReadOnlyMemory<char> AsMemory(this ICharTermAttribute text, int start)
    Parameters
    Type Name Description
    ICharTermAttribute text

    The target string.

    int start

    The index at which to begin this slice.

    Returns
    Type Description
    ReadOnlyMemory<char>

    Returns default when text is null.

    Remarks

    Returns default when text is null.

    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    start is not in range of text (start is <0 or >text.Length).

    AsMemory(ICharTermAttribute, int, int)

    Creates a new ReadOnlyMemory<T> over the portion of the target string.

    Declaration
    public static ReadOnlyMemory<char> AsMemory(this ICharTermAttribute text, int start, int length)
    Parameters
    Type Name Description
    ICharTermAttribute text

    The target string.

    int start

    The index at which to begin this slice.

    int length

    The desired length for the slice (exclusive).

    Returns
    Type Description
    ReadOnlyMemory<char>

    The read-only character memory representation of the string, or default if text is null.

    Remarks

    Returns default when text is null.

    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    start, length, or start + length is not in the range of text.

    AsMemory(ICharTermAttribute, Range)

    Creates a new ReadOnlyMemory<T> over the portion of the target string.

    Declaration
    public static ReadOnlyMemory<char> AsMemory(this ICharTermAttribute text, Range range)
    Parameters
    Type Name Description
    ICharTermAttribute text

    The target string.

    Range range

    The range used to indicate the start and length of the sliced string.

    Returns
    Type Description
    ReadOnlyMemory<char>

    The read-only character memory representation of the string.

    Exceptions
    Type Condition
    ArgumentNullException

    text is null.

    ArgumentOutOfRangeException

    range's start or end index is not within the bounds of the string. -or- range's start index is greater than its end index.

    AsSpan(ICharTermAttribute)

    Creates a new readonly span over the portion of the target string.

    Declaration
    public static ReadOnlySpan<char> AsSpan(this ICharTermAttribute text)
    Parameters
    Type Name Description
    ICharTermAttribute text

    The target string.

    Returns
    Type Description
    ReadOnlySpan<char>

    The read-only span representation of the string.

    Remarks

    Returns default when text is null.

    AsSpan(ICharTermAttribute, Index)

    Creates a new read-only span over a portion of the target string from a specified position to the end of the string.

    Declaration
    public static ReadOnlySpan<char> AsSpan(this ICharTermAttribute text, Index startIndex)
    Parameters
    Type Name Description
    ICharTermAttribute text

    The target string.

    Index startIndex

    The index at which to begin this slice.

    Returns
    Type Description
    ReadOnlySpan<char>

    The read-only span representation of the string.

    Exceptions
    Type Condition
    ArgumentNullException

    text is null.

    ArgumentOutOfRangeException

    startIndex is less than 0 or greater than text.Length.

    AsSpan(ICharTermAttribute, int)

    Creates a new read-only span over a portion of the target string from a specified position to the end of the string.

    Declaration
    public static ReadOnlySpan<char> AsSpan(this ICharTermAttribute text, int start)
    Parameters
    Type Name Description
    ICharTermAttribute text

    The target string.

    int start

    The index at which to begin this slice.

    Returns
    Type Description
    ReadOnlySpan<char>

    The read-only span representation of the string.

    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    start is less than 0 or greater than text.Length.

    ArgumentNullException

    text is null.

    AsSpan(ICharTermAttribute, int, int)

    Creates a new read-only span over a portion of the target string from a specified position for a specified number of characters.

    Declaration
    public static ReadOnlySpan<char> AsSpan(this ICharTermAttribute text, int start, int length)
    Parameters
    Type Name Description
    ICharTermAttribute text

    The target string.

    int start

    The index at which to begin this slice.

    int length

    The desired length for the slice.

    Returns
    Type Description
    ReadOnlySpan<char>

    The read-only span representation of the string.

    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    start, length, or start + length is not in the range of text.

    AsSpan(ICharTermAttribute, Range)

    Creates a new read-only span over a portion of a target string using the range start and end indexes.

    Declaration
    public static ReadOnlySpan<char> AsSpan(this ICharTermAttribute text, Range range)
    Parameters
    Type Name Description
    ICharTermAttribute text

    The target string.

    Range range

    The range that has start and end indexes to use for slicing the string.

    Returns
    Type Description
    ReadOnlySpan<char>

    The read-only span representation of the string.

    Exceptions
    Type Condition
    ArgumentNullException

    text is null.

    ArgumentOutOfRangeException

    range's start or end index is not within the bounds of the string. -or- range's start index is greater than its end index.

    Back to top Copyright © 2025 The Apache Software Foundation, Licensed under the Apache License, Version 2.0
    Apache Lucene.Net, Lucene.Net, Apache, the Apache feather logo, and the Apache Lucene.Net project logo are trademarks of The Apache Software Foundation.
    All other marks mentioned may be trademarks or registered trademarks of their respective owners.