Skip to content
This repository has been archived by the owner on Aug 7, 2022. It is now read-only.

Commit

Permalink
Created Do function for IEnumerable
Browse files Browse the repository at this point in the history
  • Loading branch information
erri120 committed Nov 29, 2019
1 parent 266eef4 commit 562c174
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 4 additions & 7 deletions OMODFramework/Scripting/DotNetScriptHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,15 @@ private static byte[] Compile(string code, ScriptType type)
throw new OMODFrameworkException("The script could not be compiled!");

var stdout = ""; //TODO: create interface for script outputs so it lands at the end user
foreach (var s in results.Output)
{
stdout += s + Environment.NewLine;
}
results.Output.Do(s => { stdout += s + Environment.NewLine; });

if (results.Errors.HasErrors || results.Errors.HasWarnings)
{
var e = "";
var w = "";
foreach (CompilerError ce in results.Errors)
results.Errors.Do(o =>
{
var ce = (CompilerError)o;
if (ce.IsWarning)
{
w += $"Warning on Line {ce.Line}: {ce.ErrorText}\n";
Expand All @@ -89,8 +87,7 @@ private static byte[] Compile(string code, ScriptType type)
{
e += $"Error on Line {ce.Line}: {ce.ErrorText}\n";
}
}

});
if(results.Errors.HasErrors)
throw new OMODFrameworkException($"Problems during script compilation: \n{e}\n{w}");
}
Expand Down
6 changes: 6 additions & 0 deletions OMODFramework/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ You should have received a copy of the GNU General Public License
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using Directory = Alphaleonis.Win32.Filesystem.Directory;
Expand Down Expand Up @@ -103,5 +104,10 @@ internal static void Do<T>(this IEnumerable<T> coll, Action<T> f)
{
foreach (var i in coll) f(i);
}

internal static void Do(this IEnumerable coll, Action<object> f)
{
foreach (var i in coll) f(i);
}
}
}

0 comments on commit 562c174

Please sign in to comment.