-
-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PredefinedTypesHelper: Fix loading types from System.Data.Entity and …
…EntityFramework (#807) * PredefinedTypesHelper: Fix loading types from System.Data.Entity and EntityFramework * . * type * Add Demo * . * . * bs * 12 * 12test * . * . * fs * .
- Loading branch information
Showing
29 changed files
with
425 additions
and
349 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Serilog" Version="3.1.1" /> | ||
<PackageReference Include="Serilog.Exceptions" Version="8.4.0" /> | ||
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" /> | ||
<!--<PackageReference Include="System.Linq.Dynamic.Core" Version="1.3.13" />--> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\System.Linq.Dynamic.Core\System.Linq.Dynamic.Core.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System.Diagnostics; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq.Dynamic.Core; | ||
using System.Reflection; | ||
using Serilog; | ||
using Serilog.Exceptions; | ||
|
||
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve; | ||
|
||
Log.Logger = new LoggerConfiguration() | ||
.Enrich.WithExceptionDetails() | ||
.WriteTo.Console(outputTemplate: "{Timestamp:HH:mm:ss.fff} [{Level}] {Message}{NewLine}{Exception}") | ||
.CreateLogger(); | ||
|
||
var customers = new List<Customer> | ||
{ | ||
new(Guid.NewGuid(), [ | ||
new Order(Guid.NewGuid()), | ||
new Order(Guid.NewGuid()), | ||
new Order(Guid.NewGuid()), | ||
new Order(Guid.NewGuid()) | ||
]), | ||
new(Guid.NewGuid(), [ | ||
new Order(Guid.NewGuid()), | ||
new Order(Guid.NewGuid()) | ||
]) | ||
}; | ||
|
||
Log.Information("--- LoadAdditionalAssembliesFromCurrentDomainBaseDirectory = {load} ---", false); | ||
var result = customers | ||
.AsQueryable() | ||
.Where("Orders.Count >= @0", 3) | ||
.OrderBy("Orders.Count") | ||
.ToList(); | ||
Log.Information("Found {Count} customers: {Customers}", result.Count, result); | ||
|
||
Log.Information(new string('*', 80)); | ||
|
||
Log.Information("--- LoadAdditionalAssembliesFromCurrentDomainBaseDirectory = {load} ---", true); | ||
var config = new ParsingConfig | ||
{ | ||
LoadAdditionalAssembliesFromCurrentDomainBaseDirectory = true | ||
}; | ||
var result2 = customers | ||
.AsQueryable() | ||
.Where(config, "Orders.Count >= @0", 3) | ||
.OrderBy("Orders.Count") | ||
.ToList(); | ||
Log.Information("Found {Count} customers: {Customers}", result2.Count, result2); | ||
|
||
return; | ||
|
||
static Assembly? CurrentDomainOnAssemblyResolve(object? sender, ResolveEventArgs resolveEventArgs) | ||
{ | ||
Log.Warning("Attempted to resolve assembly {Name} by {RequestingAssembly}", resolveEventArgs.Name, resolveEventArgs.RequestingAssembly?.GetName().Name); | ||
|
||
return null; | ||
} | ||
|
||
[SuppressMessage("Design", "CA1050:Declare types in namespaces")] | ||
[SuppressMessage("ReSharper", "NotAccessedPositionalProperty.Global")] | ||
public record Order(Guid Id); | ||
|
||
[SuppressMessage("Design", "CA1050:Declare types in namespaces")] | ||
[SuppressMessage("ReSharper", "NotAccessedPositionalProperty.Global")] | ||
public record Customer(Guid Id, List<Order> Orders); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<Target Name="CopyDllAfterBuild" AfterTargets="PostBuildEvent"> | ||
<Copy | ||
SourceFiles="$(OutputPath)Demo.Plugin.dll" | ||
DestinationFolder="../Demo.Host/bin/Debug/net8.0" /> | ||
</Target> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Demo.Plugin; | ||
|
||
public static class MyPlugin | ||
{ | ||
public static void Print() | ||
{ | ||
Console.WriteLine("Hello, World!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
if (Test-Path -Path ".\output") { | ||
Remove-Item -Force -Recurse -Path ".\output\" | ||
} | ||
else { | ||
New-Item -Path ".\output" -ItemType Directory | ||
} | ||
|
||
|
||
Write-Host "Build solution..." | ||
|
||
dotnet build .\LinqCoreDemo.sln --nologo --configuration "Debug" | ||
|
||
Write-Host "Publish projects..." | ||
dotnet publish .\src\Demo.Plugin\Demo.Plugin.csproj --nologo --no-build --configuration "Debug" --output .\output | ||
dotnet publish .\src\Demo.Host\Demo.Host.csproj --nologo --no-build --configuration "Debug" --output .\output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace EntityFramework.DynamicLinq; | ||
|
||
/// <summary> | ||
/// A dummy class to determine if the assembly is using EntityFramework. | ||
/// </summary> | ||
public struct EFType | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.