BadScript 2
Loading...
Searching...
No Matches
BadScript2.IO.BadFileSystem Class Reference

Public interface for the filesystem abstraction of the BadScript Engine. More...

Static Public Member Functions

static void SetFileSystem (IFileSystem fileSystem)
 Sets the FileSystem implementation.
 
static void WriteAllText (string path, string contents)
 Wrapper for IFileSystem.OpenWrite that creates the file if it does not exist.
 
static void WriteAllText (this IFileSystem fileSystem, string path, string contents)
 
static string ReadAllText (this IFileSystem fileSystem, string path)
 
static string ReadAllText (string path)
 Wrapper for IFileSystem.OpenRead
 
static IEnumerable< string > ReadAllLines (this IFileSystem fileSystem, string path)
 
static IEnumerable< string > ReadAllLines (string path)
 Wrapper for IFileSystem.OpenRead
 
static void WriteAllLines (this IFileSystem fileSystem, string path, IEnumerable< string > lines)
 
static void WriteAllLines (string path, IEnumerable< string > lines)
 Wrapper for IFileSystem.OpenWrite that creates the file if it does not exist.
 

Properties

static IFileSystem Instance [get]
 File System implementation.
 

Static Private Attributes

static ? IFileSystem s_FileSystem = new BadSystemFileSystem()
 File System implementation.
 

Detailed Description

Public interface for the filesystem abstraction of the BadScript Engine.

Definition at line 10 of file BadFileSystem.cs.

Member Function Documentation

◆ ReadAllLines() [1/2]

static IEnumerable< string > BadScript2.IO.BadFileSystem.ReadAllLines ( string  path)
static

Wrapper for IFileSystem.OpenRead

Parameters
pathPath of the file

Definition at line 84 of file BadFileSystem.cs.

85 {
86 return Instance.ReadAllLines(path);
87 }
static IFileSystem Instance
File System implementation.

◆ ReadAllLines() [2/2]

static IEnumerable< string > BadScript2.IO.BadFileSystem.ReadAllLines ( this IFileSystem  fileSystem,
string  path 
)
static

Definition at line 68 of file BadFileSystem.cs.

69 {
70 using Stream s = fileSystem.OpenRead(path);
71 using StreamReader sw = new StreamReader(s);
72
73
74 while (!sw.EndOfStream)
75 {
76 yield return sw.ReadLine() ?? "";
77 }
78 }

◆ ReadAllText() [1/2]

static string BadScript2.IO.BadFileSystem.ReadAllText ( string  path)
static

Wrapper for IFileSystem.OpenRead

Parameters
pathPath of the file

Definition at line 62 of file BadFileSystem.cs.

63 {
64 return Instance.ReadAllText(path);
65 }

◆ ReadAllText() [2/2]

static string BadScript2.IO.BadFileSystem.ReadAllText ( this IFileSystem  fileSystem,
string  path 
)
static

Definition at line 50 of file BadFileSystem.cs.

51 {
52 using Stream s = fileSystem.OpenRead(path);
53 using StreamReader sw = new StreamReader(s);
54
55 return sw.ReadToEnd();
56 }

◆ SetFileSystem()

static void BadScript2.IO.BadFileSystem.SetFileSystem ( IFileSystem  fileSystem)
static

Sets the FileSystem implementation.

Parameters
fileSystemThe FileSystem implementation

Definition at line 28 of file BadFileSystem.cs.

29 {
30 s_FileSystem = fileSystem;
31 }
static ? IFileSystem s_FileSystem
File System implementation.

◆ WriteAllLines() [1/2]

static void BadScript2.IO.BadFileSystem.WriteAllLines ( string  path,
IEnumerable< string >  lines 
)
static

Wrapper for IFileSystem.OpenWrite that creates the file if it does not exist.

Parameters
pathPath of the file
lineslines to be written

Definition at line 105 of file BadFileSystem.cs.

106 {
107 Instance.WriteAllLines(path, lines);
108 }

◆ WriteAllLines() [2/2]

static void BadScript2.IO.BadFileSystem.WriteAllLines ( this IFileSystem  fileSystem,
string  path,
IEnumerable< string >  lines 
)
static

Definition at line 89 of file BadFileSystem.cs.

90 {
91 using Stream s = fileSystem.OpenWrite(path, BadWriteMode.CreateNew);
92 using StreamWriter sw = new StreamWriter(s);
93
94 foreach (string line in lines)
95 {
96 sw.WriteLine(line);
97 }
98 }
BadWriteMode
The Write Modes of the File System Abstraction.

◆ WriteAllText() [1/2]

static void BadScript2.IO.BadFileSystem.WriteAllText ( string  path,
string  contents 
)
static

Wrapper for IFileSystem.OpenWrite that creates the file if it does not exist.

Parameters
pathPath of the file
contentsContents to be written

Definition at line 38 of file BadFileSystem.cs.

39 {
40 Instance.WriteAllText(path, contents);
41 }

◆ WriteAllText() [2/2]

static void BadScript2.IO.BadFileSystem.WriteAllText ( this IFileSystem  fileSystem,
string  path,
string  contents 
)
static

Definition at line 43 of file BadFileSystem.cs.

44 {
45 using Stream s = fileSystem.OpenWrite(path, BadWriteMode.CreateNew);
46 using StreamWriter sw = new StreamWriter(s);
47 sw.Write(contents);
48 }

Member Data Documentation

◆ s_FileSystem

? IFileSystem BadScript2.IO.BadFileSystem.s_FileSystem = new BadSystemFileSystem()
staticprivate

File System implementation.

Definition at line 15 of file BadFileSystem.cs.

Property Documentation

◆ Instance

IFileSystem BadScript2.IO.BadFileSystem.Instance
staticget

File System implementation.

Exceptions
InvalidOperationExceptionGets thrown if the FileSystem is not set

Definition at line 21 of file BadFileSystem.cs.


The documentation for this class was generated from the following file: