Skip to content

Commit

Permalink
NTypewriter.Runtime.v0.5.5.7
Browse files Browse the repository at this point in the history
  • Loading branch information
NeVeSpl committed Mar 7, 2024
1 parent f43e26d commit 0309787
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions NTypewriter.Runtime/NTypewriter.Runtime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<TargetFramework>netstandard2.0</TargetFramework>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>xKey.snk</AssemblyOriginatorKeyFile>
<Version>0.5.5</Version>
<AssemblyVersion>0.5.5</AssemblyVersion>
<Version>0.5.5.7</Version>
<AssemblyVersion>0.5.5.7</AssemblyVersion>
<Authors>NeVeSpl</Authors>
<Company>NeVeSpl</Company>
<Copyright>(c) NTypewriter</Copyright>
Expand Down
20 changes: 17 additions & 3 deletions NTypewriter.Runtime/Scripting/ExpressionCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using Microsoft.CodeAnalysis;
Expand Down Expand Up @@ -49,13 +51,25 @@ public ExpressionCompiler(IEnumerable<MetadataReference> references)

public Func<object, bool> CompilePredicate(string predicate, Type type)
{
//Func<object, bool> func = x => { return new Func<object, bool>(x => true)(x as object); };
try
{
return CompilePredicateInternal(predicate, type);
}
catch (Exception ex) when (ex is not Microsoft.CodeAnalysis.Scripting.CompilationErrorException)
{
Trace.TraceError(ex.ToString());
}
return null;
}

private Func<object, bool> CompilePredicateInternal(string predicate, Type type)
{
var lambda = $"x => {{ return new Func<{type.Name}, bool>({predicate})(({type.Name})x); }}";

var options = ScriptOptions.Default.AddReferences(MetadataReferences).AddImports(Imports);
var func = CSharpScript.EvaluateAsync<Func<object, bool>>(lambda, options).Result;

var func = CSharpScript.EvaluateAsync<Func<object, bool>>(lambda, options).GetAwaiter().GetResult();
return func;
}
}
}
}
3 changes: 2 additions & 1 deletion NTypewriter.Runtime/UserCode/UserCodeLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,10 @@ static UserCodeLoader()
}
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
var asmName = new AssemblyName(args.Name);
var currentDomain = sender as AppDomain;
var assemblies = currentDomain.GetAssemblies();
var assembly = assemblies.FirstOrDefault(x => x.FullName == args.Name);
var assembly = assemblies.FirstOrDefault(x => x.GetName().FullName == asmName.FullName);
return assembly;
}
#endregion
Expand Down

0 comments on commit 0309787

Please sign in to comment.