Merge pull request #755 from KingLuigi4932/patch-3

Fixing WriteAllLines issue
This commit is contained in:
fanoI 2017-09-02 20:54:15 +02:00 committed by GitHub
commit cf08368c9e
2 changed files with 17 additions and 24 deletions

View file

@ -617,20 +617,18 @@ namespace Cosmos.Kernel.Tests.Fat
mDebugger.Send("END TEST"); mDebugger.Send("END TEST");
mDebugger.Send(""); mDebugger.Send("");
} }
// Generic methods on arrays don't work, see https://github.com/CosmosOS/Cosmos/issues/583 string[] contents = { "One", "Two", "Three" };
// File.WriteAllLines(@"0:\test3.txt", contents);
//string[] contents = { "One", "Two", "Three" }; mDebugger.Send("Text written");
//File.WriteAllLines(@"0:\test3.txt", contents); mDebugger.Send("Now reading with ReadAllLines()");
//mDebugger.Send("Text written"); string[] readLines = File.ReadAllLines(@"0:\test3.txt");
//mDebugger.Send("Now reading with ReadAllLines()"); mDebugger.Send("Contents retrieved after writing");
//string[] readLines = File.ReadAllLines(@"0:\test3.txt"); for (int i = 0; i < readLines.Length; i++)
//mDebugger.Send("Contents retrieved after writing"); {
//for (int i = 0; i < readLines.Length; i++) mDebugger.Send(readLines[i]);
//{ }
// mDebugger.Send(readLines[i]); Assert.IsTrue(StringArrayAreEquals(contents, readLines), "Contents of test3.txt was written incorrectly!");
//}
//Assert.IsTrue(StringArrayAreEquals(contents, readLines), "Contents of test3.txt was written incorrectly!");
#if false #if false
// TODO maybe the more correct test is to implement ReadAllLines and then check that two arrays are equals // TODO maybe the more correct test is to implement ReadAllLines and then check that two arrays are equals
var xContents = File.ReadAllText(@"0:\test3.txt"); var xContents = File.ReadAllText(@"0:\test3.txt");

View file

@ -119,19 +119,14 @@ namespace Cosmos.System_Plugs.System.IO
return result; return result;
} }
public static void WriteAllLines(string aFile, IEnumerable<string> contents) public static void WriteAllLines(string aFile, string[] contents)
{ {
string text = null; string text = String.Join(Environment.NewLine, contents);
foreach (var line in contents)
{
text = string.Concat(text, line, Environment.NewLine);
}
Global.mFileSystemDebugger.SendInternal("Writing contents"); Global.mFileSystemDebugger.SendInternal("Writing contents");
Global.mFileSystemDebugger.SendInternal(text); Global.mFileSystemDebugger.SendInternal(text);
WriteAllText(aFile, text); WriteAllText(aFile, text);
} }