Show / Hide Table of Contents

Class TextFile

This class represents a text file with data.

Inheritance
System.Object
TextFile
TextInteractor
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: TextInteractor
Assembly: TextInteractor.dll
Syntax
public abstract class TextFile

Constructors

| Improve this Doc View Source

TextFile(String)

Initializes a new instance of the TextFile class.

Declaration
public TextFile(string filePath)
Parameters
Type Name Description
System.String filePath

The path to the textFile.

| Improve this Doc View Source

TextFile(String, ILogger)

Initializes a new instance of the TextFile class. We also open the file.

Declaration
public TextFile(string filePath, ILogger logger)
Parameters
Type Name Description
System.String filePath

The path to the textFile.

Microsoft.Extensions.Logging.ILogger logger

Logger that is passed in.

Properties

| Improve this Doc View Source

FilePath

Gets or sets the FilePath The full file path of the text file.

Declaration
public string FilePath { get; protected set; }
Property Value
Type Description
System.String
| Improve this Doc View Source

Logger

Gets or sets the logger that will be used by TextFile.

Declaration
public ILogger Logger { get; set; }
Property Value
Type Description
Microsoft.Extensions.Logging.ILogger
| Improve this Doc View Source

Opened

Gets or sets a value indicating whether the file has been opened / not.

Declaration
public bool Opened { get; protected set; }
Property Value
Type Description
System.Boolean

Methods

| Improve this Doc View Source

Close()

This method closes the text file for reading and writing. If file not open, nothing will happen.

Declaration
public abstract bool Close()
Returns
Type Description
System.Boolean
true
if the text file successfully closes.
| Improve this Doc View Source

Compare(TextFile, String, Boolean, Boolean)

This method compares the text file with another text file.

Declaration
public abstract bool Compare(TextFile txtFile, string resultFilePath, bool ignoreWhitespace = false, bool caseInsensitive = false)
Parameters
Type Name Description
TextFile txtFile

Text file to compare.

System.String resultFilePath

Text file that shows the comparison result when different. If there is a file name conflict, we will replace the file.

System.Boolean ignoreWhitespace

Set to true if we are going to ignore whitespace during comparison. Default is false.

System.Boolean caseInsensitive

Set to true if we are going to perform case insensitive comparison. Default is false.

Returns
Type Description
System.Boolean
true
if the contents of the text files match.
| Improve this Doc View Source

Compare(TextFile, String, Int32, Int32, Int32, Int32, Boolean, Boolean)

This method compares the text file with another text file specifying the top left and bottom right coordinates. If we consider the file to be a 2D matrix of characters, the startingLine and startingIndex would be the top left corner (x, y) respectively. The endingLine and endingIndex would be the bottom right coordinate on the bottom right corner.

Declaration
public abstract bool Compare(TextFile txtFile, string resultFilePath, int startingLine, int startingIndex, int endingLine, int endingIndex, bool ignoreWhitespace = false, bool caseInsensitive = false)
Parameters
Type Name Description
TextFile txtFile

The textfile that you want to compare with.TextFile.

System.String resultFilePath

Text file that shows the comparison result when different.

System.Int32 startingLine

The line index to start the comparison.System.Int32.

System.Int32 startingIndex

The character index to start the comparison.System.Int32.

System.Int32 endingLine

The line index to stop the comparison.System.Int32.

System.Int32 endingIndex

The character index to end the comparison.System.Int32.

System.Boolean ignoreWhitespace

Set to true if we are going to ignore whitespace during comparison. Default is false.

System.Boolean caseInsensitive

Set to true if we are going to perform case insensitive comparison. Default is false.

Returns
Type Description
System.Boolean
true
if the contents of the text file match.
| Improve this Doc View Source

Find(String, Int32)

This method tries to find the expected string in the specified line.

Declaration
public abstract bool Find(string expectedString, int line)
Parameters
Type Name Description
System.String expectedString

String to be found.

System.Int32 line

Line in the file to check, index starts at 1.

Returns
Type Description
System.Boolean
true
if the expected string is found at line.
| Improve this Doc View Source

FinishedReading()

This methods returns whether or not the reader is at the end of the text file.

Declaration
public abstract bool FinishedReading()
Returns
Type Description
System.Boolean
true
if the file has been finished reading.
| Improve this Doc View Source

Modify(Int32, String)

This methods modifies the textfile by replacing text in the text file.

Declaration
public abstract bool Modify(int replaceType, string args)
Parameters
Type Name Description
System.Int32 replaceType

0 means to replace once, 1 means to replaceAll, 2 means to replaceLine,3 means to replace regexSystem.Int32.

System.String args

The argsSystem.String.

Returns
Type Description
System.Boolean
true
if the modification was successful. System.Boolean.
| Improve this Doc View Source

Open()

This method opens the text file for reading and writing. If file is already open, nothing will happen.

Declaration
public abstract bool Open()
Returns
Type Description
System.Boolean
true
if the text file successfully opens.
| Improve this Doc View Source

ReadLine()

This method reads a line of characters in the file and returns the data as a string.

Declaration
public abstract string ReadLine()
Returns
Type Description
System.String

A string from the text file.

| Improve this Doc View Source

RestartReading()

This method resets the reader back to the beginning of the text file.

Declaration
public abstract void RestartReading()
  • Improve this Doc
  • View Source
Back to top Generated by DocFX