Extracted IFileWriter for OSCADObject.ToFile

Included default implementation for IFileWriter and replaceable reference in Settings.cs
This commit is contained in:
Michael Smith 2016-02-23 21:59:17 -08:00
parent 4532e7b20d
commit 7e5160d701
5 changed files with 47 additions and 2 deletions

View File

@ -328,8 +328,8 @@ namespace OSCADSharp
{
path += ".scad";
}
File.WriteAllLines(path, new string[]
Settings.FileWriter.WriteAllLines(path, new string[]
{
Settings.OSCADSharpHeader,
Settings.Globals.ToString(),

View File

@ -42,6 +42,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Scripting\DefaultFileWriter.cs" />
<Compile Include="Scripting\IFileWriter.cs" />
<Compile Include="Ids.cs" />
<Compile Include="Scripting\StatementBuilder.cs" />
<Compile Include="Settings.cs" />

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OSCADSharp.Scripting
{
internal class DefaultFileWriter : IFileWriter
{
public void WriteAllLines(string path, string[] contents)
{
File.WriteAllLines(path, contents);
}
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OSCADSharp.Scripting
{
/// <summary>
/// A class that takes text and writes to file
/// </summary>
public interface IFileWriter
{
/// <summary>
/// Writes lines of text to a file at the path specified
/// </summary>
/// <param name="path"></param>
/// <param name="contents"></param>
void WriteAllLines(string path, string[] contents);
}
}

View File

@ -23,5 +23,10 @@ namespace OSCADSharp
/// top of OpenSCAD scripts
/// </summary>
public static Variables Globals = new Variables();
/// <summary>
/// Used to write scripts to file
/// </summary>
public static IFileWriter FileWriter = new DefaultFileWriter();
}
}