Show / Hide Table of Contents

# Class ScriptFile

Contains the details and contents of an open script file.

##### Inheritance

System.Object
ScriptFile

##### 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)
System.Object.ToString()

###### Namespace:Microsoft.SqlTools.ServiceLayer.Workspace.Contracts

###### Assembly:Microsoft.SqlTools.ServiceLayer.dll

##### Syntax

    public class ScriptFile

### Constructors

| Improve this Doc View Source

#### ScriptFile()

Add a default constructor for testing

##### Declaration

    public ScriptFile()

| Improve this Doc View Source

#### ScriptFile(String, String, TextReader)

Creates a new ScriptFile instance by reading file contents from the given TextReader.

##### Declaration

    public ScriptFile(string filePath, string clientFilePath, TextReader textReader)

##### Parameters

Type | Name | Description
--- | --- | ---
System.String | filePath | The path at which the script file resides.
System.String | clientFilePath | The path which the client uses to identify the file.
System.IO.TextReader | textReader | The TextReader to use for reading the file's contents.

| Improve this Doc View Source

#### ScriptFile(String, String, String)

Creates a new ScriptFile instance with the specified file contents.

##### Declaration

    public ScriptFile(string filePath, string clientFilePath, string initialBuffer)

##### Parameters

Type | Name | Description
--- | --- | ---
System.String | filePath | The path at which the script file resides.
System.String | clientFilePath | The path which the client uses to identify the file.
System.String | initialBuffer | The initial contents of the script file.

### Properties

| Improve this Doc View Source

#### ClientFilePath

Gets or sets the path which the editor client uses to identify this file. Setter for testing purposes only virtual to allow mocking.

##### Declaration

    public virtual string ClientFilePath { get; }

##### Property Value

Type | Description
--- | ---
System.String |

| Improve this Doc View Source

#### Contents

Gets or sets a string containing the full contents of the file. Setter for testing purposes only

##### Declaration

    public virtual string Contents { get; set; }

##### Property Value

Type | Description
--- | ---
System.String |

| Improve this Doc View Source

#### FilePath

Gets the path at which this file resides.

##### Declaration

    public string FilePath { get; }

##### Property Value

Type | Description
--- | ---
System.String |

| Improve this Doc View Source

#### FileRange

Gets a BufferRange that represents the entire content range of the file.

##### Declaration

    public BufferRange FileRange { get; }

##### Property Value

Type | Description
--- | ---
BufferRange |

| Improve this Doc View Source

#### Id

Gets a unique string that identifies this file. At this time, this property returns a normalized version of the value stored in the FilePath property.

##### Declaration

    public string Id { get; }

##### Property Value

Type | Description
--- | ---
System.String |

| Improve this Doc View Source

#### IsInMemory

Gets a boolean that determines whether this file is in-memory or not (either unsaved or non-file content).

##### Declaration

    public bool IsInMemory { get; }

##### Property Value

Type | Description
--- | ---
System.Boolean |

| Improve this Doc View Source

#### SyntaxMarkers

Gets the list of syntax markers found by parsing this file's contents.

##### Declaration

    public ScriptFileMarker[] SyntaxMarkers { get; }

##### Property Value

Type | Description
--- | ---
ScriptFileMarker[] |

### Methods

| Improve this Doc View Source

#### ApplyChange(FileChange)

Applies the provided FileChange to the file's contents

##### Declaration

    public void ApplyChange(FileChange fileChange)

##### Parameters

Type | Name | Description
--- | --- | ---
FileChange | fileChange | The FileChange to apply to the file's contents.

| Improve this Doc View Source

#### CalculatePosition(BufferPosition, Int32, Int32)

Calculates a FilePosition relative to a starting BufferPosition using the given 1-based line and column offset.

##### Declaration

    public FilePosition CalculatePosition(BufferPosition originalPosition, int lineOffset, int columnOffset)

##### Parameters

Type | Name | Description
--- | --- | ---
BufferPosition | originalPosition | The original BufferPosition from which an new position should be calculated.
System.Int32 | lineOffset | The 1-based line offset added to the original position in this file.
System.Int32 | columnOffset | The 1-based column offset added to the original position in this file.

##### Returns

Type | Description
--- | ---
FilePosition | A new FilePosition instance with the resulting line and column number.

| Improve this Doc View Source

#### GetLine(Int32)

Gets a line from the file's contents.

##### Declaration

    public string GetLine(int lineNumber)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Int32 | lineNumber | The 1-based line number in the file.

##### Returns

Type | Description
--- | ---
System.String | The complete line at the given line number.

| Improve this Doc View Source

#### GetLinesInRange(BufferRange)

Gets a range of lines from the file's contents. Virtual method to allow for mocking.

##### Declaration

    public virtual string[] GetLinesInRange(BufferRange bufferRange)

##### Parameters

Type | Name | Description
--- | --- | ---
BufferRange | bufferRange | The buffer range from which lines will be extracted.

##### Returns

Type | Description
--- | ---
System.String[] | An array of strings from the specified range of the file.

| Improve this Doc View Source

#### GetOffsetAtPosition(Int32, Int32)

Calculates the zero-based character offset of a given line and column position in the file.

##### Declaration

    public int GetOffsetAtPosition(int lineNumber, int columnNumber)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Int32 | lineNumber | The 1-based line number from which the offset is calculated.
System.Int32 | columnNumber | The 1-based column number from which the offset is calculated.

##### Returns

Type | Description
--- | ---
System.Int32 | The zero-based offset for the given file position.

| Improve this Doc View Source

#### GetPositionAtOffset(Int32)

Calculates the 1-based line and column number position based on the given buffer offset.

##### Declaration

    public BufferPosition GetPositionAtOffset(int bufferOffset)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Int32 | bufferOffset | The buffer offset to convert.

##### Returns

Type | Description
--- | ---
BufferPosition | A new BufferPosition containing the position of the offset.

| Improve this Doc View Source

#### GetRangeBetweenOffsets(Int32, Int32)

Calculates the 1-based line and column number range based on the given start and end buffer offsets.

##### Declaration

    public BufferRange GetRangeBetweenOffsets(int startOffset, int endOffset)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Int32 | startOffset | The start offset of the range.
System.Int32 | endOffset | The end offset of the range.

##### Returns

Type | Description
--- | ---
BufferRange | A new BufferRange containing the positions in the offset range.

| Improve this Doc View Source

#### SetFileContents(String)

Set the script files contents

##### Declaration

    public void SetFileContents(string fileContents)

##### Parameters

Type | Name | Description
--- | --- | ---
System.String | fileContents |

| Improve this Doc View Source

#### ValidatePosition(BufferPosition)

Throws ArgumentOutOfRangeException if the given position is outside of the file's buffer extents.

##### Declaration

    public void ValidatePosition(BufferPosition bufferPosition)

##### Parameters

Type | Name | Description
--- | --- | ---
BufferPosition | bufferPosition | The position in the buffer to be validated.

| Improve this Doc View Source

#### ValidatePosition(Int32, Int32)

Throws ArgumentOutOfRangeException if the given position is outside of the file's buffer extents.

##### Declaration

    public void ValidatePosition(int line, int column)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Int32 | line | The 1-based line to be validated.
System.Int32 | column | The 1-based column to be validated.