Search Results for

    Show / Hide Table of Contents

    Class SourceText

    An abstraction of source text.

    Inheritance
    System.Object
    SourceText
    Inherited Members
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    Namespace: Loretta.CodeAnalysis.Text
    Assembly: Loretta.CodeAnalysis.dll
    Syntax
    public abstract class SourceText

    Properties

    | Improve this Doc View Source

    ChecksumAlgorithm

    Hash algorithm to use to calculate checksum of the text that's saved to PDB.

    Declaration
    public SourceHashAlgorithm ChecksumAlgorithm { get; }
    Property Value
    Type Description
    SourceHashAlgorithm
    | Improve this Doc View Source

    Container

    The container of this SourceText.

    Declaration
    public virtual SourceTextContainer Container { get; }
    Property Value
    Type Description
    SourceTextContainer
    | Improve this Doc View Source

    Encoding

    Encoding of the file that the text was read from or is going to be saved to. null if the encoding is unspecified.

    Declaration
    public abstract Encoding Encoding { get; }
    Property Value
    Type Description
    System.Text.Encoding
    Remarks

    If the encoding is not specified the source isn't debuggable. If an encoding-less SourceText is written to a file a System.Text.Encoding.UTF8 shall be used as a default.

    | Improve this Doc View Source

    Item[Int32]

    Returns a character at given position.

    Declaration
    public abstract char this[int position] { get; }
    Parameters
    Type Name Description
    System.Int32 position

    The position to get the character from.

    Property Value
    Type Description
    System.Char

    The character.

    | Improve this Doc View Source

    Length

    The length of the text in characters.

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

    Lines

    The collection of individual text lines.

    Declaration
    public TextLineCollection Lines { get; }
    Property Value
    Type Description
    TextLineCollection

    Methods

    | Improve this Doc View Source

    ContentEquals(SourceText)

    Compares the content with content of another SourceText.

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

    CopyTo(Int32, Char[], Int32, Int32)

    Copy a range of characters from this SourceText to a destination array.

    Declaration
    public abstract void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count)
    Parameters
    Type Name Description
    System.Int32 sourceIndex
    System.Char[] destination
    System.Int32 destinationIndex
    System.Int32 count
    | Improve this Doc View Source

    From(Stream, Encoding, SourceHashAlgorithm, Boolean)

    Constructs a SourceText from stream content.

    Declaration
    public static SourceText From(Stream stream, Encoding encoding = null, SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1, bool throwIfBinaryDetected = false)
    Parameters
    Type Name Description
    Stream stream

    Stream. The stream must be seekable.

    System.Text.Encoding encoding

    Data encoding to use if the stream doesn't start with Byte Order Mark specifying the encoding. System.Text.Encoding.UTF8 if not specified.

    SourceHashAlgorithm checksumAlgorithm

    Hash algorithm to use to calculate checksum of the text that's saved to PDB.

    System.Boolean throwIfBinaryDetected

    If the decoded text contains at least two consecutive NUL characters, then an is thrown.

    Returns
    Type Description
    SourceText
    Remarks

    Reads from the beginning of the stream. Leaves the stream open.

    Exceptions
    Type Condition
    System.Text.DecoderFallbackException

    If the given encoding is set to use a throwing decoder as a fallback

    | Improve this Doc View Source

    From(Byte[], Int32, Encoding, SourceHashAlgorithm, Boolean)

    Constructs a SourceText from a byte array.

    Declaration
    public static SourceText From(byte[] buffer, int length, Encoding encoding = null, SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1, bool throwIfBinaryDetected = false)
    Parameters
    Type Name Description
    System.Byte[] buffer

    The encoded source buffer.

    System.Int32 length

    The number of bytes to read from the buffer.

    System.Text.Encoding encoding

    Data encoding to use if the encoded buffer doesn't start with Byte Order Mark. System.Text.Encoding.UTF8 if not specified.

    SourceHashAlgorithm checksumAlgorithm

    Hash algorithm to use to calculate checksum of the text that's saved to PDB.

    System.Boolean throwIfBinaryDetected

    If the decoded text contains at least two consecutive NUL characters, then an is thrown.

    Returns
    Type Description
    SourceText

    The decoded text.

    Exceptions
    Type Condition
    System.Text.DecoderFallbackException

    If the given encoding is set to use a throwing decoder as a fallback

    | Improve this Doc View Source

    From(String, Encoding, SourceHashAlgorithm)

    Constructs a SourceText from text in a string.

    Declaration
    public static SourceText From(string text, Encoding encoding = null, SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1)
    Parameters
    Type Name Description
    System.String text

    Text.

    System.Text.Encoding encoding

    Encoding of the file that the text was read from or is going to be saved to. null if the encoding is unspecified. If the encoding is not specified the resulting SourceText isn't debuggable. If an encoding-less SourceText is written to a file a System.Text.Encoding.UTF8 shall be used as a default.

    SourceHashAlgorithm checksumAlgorithm

    Hash algorithm to use to calculate checksum of the text that's saved to PDB.

    Returns
    Type Description
    SourceText
    | Improve this Doc View Source

    From(TextReader, Int32, Encoding, SourceHashAlgorithm)

    Constructs a SourceText from text in a string.

    Declaration
    public static SourceText From(TextReader reader, int length, Encoding encoding = null, SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1)
    Parameters
    Type Name Description
    TextReader reader

    TextReader

    System.Int32 length

    length of content from reader

    System.Text.Encoding encoding

    Encoding of the file that the reader was read from or is going to be saved to. null if the encoding is unspecified. If the encoding is not specified the resulting SourceText isn't debuggable. If an encoding-less SourceText is written to a file a System.Text.Encoding.UTF8 shall be used as a default.

    SourceHashAlgorithm checksumAlgorithm

    Hash algorithm to use to calculate checksum of the text that's saved to PDB.

    Returns
    Type Description
    SourceText
    | Improve this Doc View Source

    GetChangeRanges(SourceText)

    Gets the set of TextChangeRange that describe how the text changed between this text an older version. This may be multiple detailed changes or a single change encompassing the entire text.

    Declaration
    public virtual IReadOnlyList<TextChangeRange> GetChangeRanges(SourceText oldText)
    Parameters
    Type Name Description
    SourceText oldText
    Returns
    Type Description
    IReadOnlyList<TextChangeRange>
    | Improve this Doc View Source

    GetChecksum()

    Returns the checksum for this text.

    Declaration
    public ImmutableArray<byte> GetChecksum()
    Returns
    Type Description
    ImmutableArray<System.Byte>
    | Improve this Doc View Source

    GetSubText(TextSpan)

    Gets a SourceText that contains the characters in the specified span of this text.

    Declaration
    public virtual SourceText GetSubText(TextSpan span)
    Parameters
    Type Name Description
    TextSpan span
    Returns
    Type Description
    SourceText
    | Improve this Doc View Source

    GetSubText(Int32)

    Returns a SourceText that has the contents of this text including and after the start position.

    Declaration
    public SourceText GetSubText(int start)
    Parameters
    Type Name Description
    System.Int32 start
    Returns
    Type Description
    SourceText
    | Improve this Doc View Source

    GetTextChanges(SourceText)

    Gets the set of TextChange that describe how the text changed between this text and an older version. This may be multiple detailed changes or a single change encompassing the entire text.

    Declaration
    public virtual IReadOnlyList<TextChange> GetTextChanges(SourceText oldText)
    Parameters
    Type Name Description
    SourceText oldText
    Returns
    Type Description
    IReadOnlyList<TextChange>
    | Improve this Doc View Source

    Replace(TextSpan, String)

    Returns a new SourceText with the specified span of characters replaced by the new text.

    Declaration
    public SourceText Replace(TextSpan span, string newText)
    Parameters
    Type Name Description
    TextSpan span
    System.String newText
    Returns
    Type Description
    SourceText
    | Improve this Doc View Source

    Replace(Int32, Int32, String)

    Returns a new SourceText with the specified range of characters replaced by the new text.

    Declaration
    public SourceText Replace(int start, int length, string newText)
    Parameters
    Type Name Description
    System.Int32 start
    System.Int32 length
    System.String newText
    Returns
    Type Description
    SourceText
    | Improve this Doc View Source

    ToString()

    Provides a string representation of the SourceText.

    Declaration
    public override string ToString()
    Returns
    Type Description
    System.String
    Overrides
    System.Object.ToString()
    | Improve this Doc View Source

    ToString(TextSpan)

    Gets a string containing the characters in specified span.

    Declaration
    public virtual string ToString(TextSpan span)
    Parameters
    Type Name Description
    TextSpan span
    Returns
    Type Description
    System.String
    | Improve this Doc View Source

    WithChanges(IEnumerable<TextChange>)

    Constructs a new SourceText from this text with the specified changes.

    Declaration
    public virtual SourceText WithChanges(IEnumerable<TextChange> changes)
    Parameters
    Type Name Description
    IEnumerable<TextChange> changes
    Returns
    Type Description
    SourceText
    | Improve this Doc View Source

    WithChanges(TextChange[])

    Constructs a new SourceText from this text with the specified changes. If any changes are not in bounds of this SourceText. If any changes overlap other changes.

    Declaration
    public SourceText WithChanges(params TextChange[] changes)
    Parameters
    Type Name Description
    TextChange[] changes
    Returns
    Type Description
    SourceText
    Remarks

    Changes do not have to be in sorted order. However, WithChanges(IEnumerable<TextChange>) will perform better if they are.

    | Improve this Doc View Source

    Write(TextWriter, CancellationToken)

    Write this SourceText to a text writer.

    Declaration
    public void Write(TextWriter textWriter, CancellationToken cancellationToken = null)
    Parameters
    Type Name Description
    TextWriter textWriter
    CancellationToken cancellationToken
    | Improve this Doc View Source

    Write(TextWriter, TextSpan, CancellationToken)

    Write a span of text to a text writer.

    Declaration
    public virtual void Write(TextWriter writer, TextSpan span, CancellationToken cancellationToken = null)
    Parameters
    Type Name Description
    TextWriter writer
    TextSpan span
    CancellationToken cancellationToken
    • Improve this Doc
    • View Source
    ☀
    ☾
    In This Article
    Back to top

    Copyright (c) LorettaDevs

    Generated by DocFX

    ☀
    ☾