Skip to content

Commit

Permalink
try to make work lambda expression in NTypewriter.Online
Browse files Browse the repository at this point in the history
  • Loading branch information
NeVeSpl committed Mar 6, 2024
1 parent bf82681 commit a645ed1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
30 changes: 26 additions & 4 deletions NTypewriter.Online/Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using NTypewriter.CodeModel.Functions;
using NTypewriter.CodeModel;
using NTypewriter.Editor.Config;
using NTypewriter.Online.Adapters;
using NTypewriter.Ports;
using NTypewriter.Runtime;
Expand All @@ -27,12 +30,31 @@ public async Task Initialize(string baseUri)
BaseAddress = new Uri(baseUri)
};

var refTypes = new[]
{
typeof(IEditorConfig),
typeof(ICodeModel),
typeof(ActionFunctions),
typeof(System.Text.Json.JsonSerializer),
};

var references = new List<MetadataReference>();
foreach (var assembly in assemblies.Where(x => !x.IsDynamic && !string.IsNullOrWhiteSpace(x.Location)))
{
Stream stream = await client.GetStreamAsync($"_framework/_bin/{assembly.Location}");
references.Add(MetadataReference.CreateFromStream(stream));
Debug.WriteLine($"=> MetadataReference for : {assembly.Location}");
{
try
{
Debug.WriteLine($"=> MetadataReference for {assembly.GetName().Name} : {assembly.Location}");
Stream stream = await client.GetStreamAsync($"_framework/_bin/{assembly.Location}");
var portableExecutableReference = MetadataReference.CreateFromStream(stream);
if (portableExecutableReference != null )
{
references.Add(portableExecutableReference);
}
}
catch (Exception ex)
{

}
}

References = references;
Expand Down
3 changes: 2 additions & 1 deletion NTypewriter.Runtime/Scripting/ExpressionCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public class ExpressionCompiler : IExpressionCompiler
private static readonly string[] Imports =
[
"System",
"NTypewriter.CodeModel",
"NTypewriter.CodeModel",
"NTypewriter.CodeModel.Functions",
];
private readonly IEnumerable<MetadataReference> MetadataReferences;

Expand Down
2 changes: 1 addition & 1 deletion NTypewriter/Internals/Functions/LINQFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal class LINQFunctions
{
/// <summary>
/// Filters a sequence of values based on a predicate.
/// Predicate uses C# lambda syntax, the same one that used by LINQ Where method
/// Predicate uses C# lambda syntax, the same one that is used by LINQ Where method
/// </summary>
public static IEnumerable<object> Where(MainTemplateContext context, IEnumerable<object> source, string predicate)
{
Expand Down

0 comments on commit a645ed1

Please sign in to comment.