Class TextFile
This class represents a text file with data.
Inherited Members
Namespace: TextInteractor
Assembly: TextInteractor.dll
Syntax
public abstract class TextFile
Constructors
| Improve this Doc View SourceTextFile(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. |
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 SourceFilePath
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 |
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 |
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 SourceClose()
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 | if the text file successfully closes.
|
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 | if the contents of the text files match.
|
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 | if the contents of the text file match.
|
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 | if the expected string is found at line.
|
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 | if the file has been finished reading.
|
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 | if the modification was successful. System.Boolean.
|
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 | if the text file successfully opens.
|
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. |
RestartReading()
This method resets the reader back to the beginning of the text file.
Declaration
public abstract void RestartReading()