Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update projects for .NET 8.0 and 9.0 support #648

Merged
merged 9 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion benchmark/RulesEngineBenchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
using System;
using System.Collections.Generic;
using System.IO;
using BenchmarkDotNet.Jobs;
using System.Text.Json;

namespace RulesEngineBenchmark
{
using System.Text.Json;

[MemoryDiagnoser]
[SimpleJob(RuntimeMoniker.Net60)]
[SimpleJob(RuntimeMoniker.Net80)]
[SimpleJob(RuntimeMoniker.Net90)]
public class REBenchmark
{
private readonly RulesEngine.RulesEngine rulesEngine;
Expand Down
8 changes: 4 additions & 4 deletions benchmark/RulesEngineBenchmark/RulesEngineBenchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
<!--<PackageReference Include="RulesEngine" Version="3.0.2" />-->
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<!--<PackageReference Include="RulesEngine" Version="3.0.2" />-->
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\RulesEngine\RulesEngine.csproj" />
<ProjectReference Include="..\..\src\RulesEngine\RulesEngine.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions demo/DemoApp.EFDataExample/DemoApp.EFDataExample.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<RootNamespace>DemoApp.EFDataExample</RootNamespace>
<AssemblyName>DemoApp.EFDataExample</AssemblyName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions demo/DemoApp/DemoApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<StartupObject>DemoApp.Program</StartupObject>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../../src/RulesEngine/RulesEngine.csproj" />
<ProjectReference Include="..\DemoApp.EFDataExample\DemoApp.EFDataExample.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="Workflows\Discount.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.0",
"version": "9.0.0",
"rollForward": "latestFeature",
"allowPrerelease": false
}
Expand Down
54 changes: 30 additions & 24 deletions src/RulesEngine/HelperFunctions/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,46 @@ public static object GetTypedObject(dynamic input)
}
public static Type CreateAbstractClassType(dynamic input)
{
List<DynamicProperty> props = new List<DynamicProperty>();
List<DynamicProperty> props = [];

if (input == null)
if (input is System.Text.Json.JsonElement jsonElement)
{
if (jsonElement.ValueKind == System.Text.Json.JsonValueKind.Null)
{
return typeof(object);
}
}
else if (input == null)
{
return typeof(object);
}
if (!(input is ExpandoObject))

if (input is not ExpandoObject expandoObject)
{
return input.GetType();
}

else
foreach (var expando in expandoObject)
{
foreach (var expando in (IDictionary<string, object>)input)
Type value;
if (expando.Value is IList list)
{
Type value;
if (expando.Value is IList)
if (list.Count == 0)
{
if (((IList)expando.Value).Count == 0)
value = typeof(List<object>);
else
{
var internalType = CreateAbstractClassType(((IList)expando.Value)[0]);
value = new List<object>().Cast(internalType).ToList(internalType).GetType();
}

value = typeof(List<object>);
}
else
{
value = CreateAbstractClassType(expando.Value);
var internalType = CreateAbstractClassType(list[0]);
value = new List<object>().Cast(internalType).ToList(internalType).GetType();
}
props.Add(new DynamicProperty(expando.Key, value));

}
else
{
value = CreateAbstractClassType(expando.Value);
}
props.Add(new DynamicProperty(expando.Key, value));
}

var type = DynamicClassFactory.CreateType(props);
Expand All @@ -67,15 +74,15 @@ public static Type CreateAbstractClassType(dynamic input)

public static object CreateObject(Type type, dynamic input)
{
if (!(input is ExpandoObject))
if (input is not ExpandoObject expandoObject)
{
return Convert.ChangeType(input, type);
}
object obj = Activator.CreateInstance(type);
var obj = Activator.CreateInstance(type);

var typeProps = type.GetProperties().ToDictionary(c => c.Name);

foreach (var expando in (IDictionary<string, object>)input)
foreach (var expando in expandoObject)
{
if (typeProps.ContainsKey(expando.Key) &&
expando.Value != null && (expando.Value.GetType().Name != "DBNull" || expando.Value != DBNull.Value))
Expand All @@ -87,14 +94,13 @@ public static object CreateObject(Type type, dynamic input)
var propType = propInfo.PropertyType;
val = CreateObject(propType, expando.Value);
}
else if (expando.Value is IList)
else if (expando.Value is IList temp)
{
var internalType = propInfo.PropertyType.GenericTypeArguments.FirstOrDefault() ?? typeof(object);
var temp = (IList)expando.Value;
var newList = new List<object>().Cast(internalType).ToList(internalType);
for (int i = 0; i < temp.Count; i++)
foreach (var t in temp)
{
var child = CreateObject(internalType, temp[i]);
var child = CreateObject(internalType, t);
newList.Add(child);
};
val = newList;
Expand Down
39 changes: 20 additions & 19 deletions src/RulesEngine/RulesEngine.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net6.0;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0;net9.0;netstandard2.0</TargetFrameworks>
<LangVersion>13.0</LangVersion>
<Version>5.0.4</Version>
<Copyright>Copyright (c) Microsoft Corporation.</Copyright>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageProjectUrl>https://github.com/microsoft/RulesEngine</PackageProjectUrl>
<Authors>Abbas Cyclewala</Authors>
<Description>Rules Engine is a package for abstracting business logic/rules/policies out of the system. This works in a very simple way by giving you an ability to put your rules in a store outside the core logic of the system thus ensuring that any change in rules doesn't affect the core system.</Description>
<PackageReleaseNotes>https://github.com/microsoft/RulesEngine/blob/main/CHANGELOG.md</PackageReleaseNotes>
<PackageTags>BRE, Rules Engine, Abstraction</PackageTags>
<PackageReleaseNotes>https://github.com/microsoft/RulesEngine/blob/main/CHANGELOG.md</PackageReleaseNotes>
<PackageTags>BRE, Rules Engine, Abstraction</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

Expand All @@ -33,27 +34,27 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="FastExpressionCompiler" Version="4.1.0" />
<PackageReference Include="FluentValidation" Version="11.9.0" />

<PackageReference Include="System.Linq.Dynamic.Core" Version="1.6.0" />

<PackageReference Include="FastExpressionCompiler" Version="5.0.2" />
<PackageReference Include="FluentValidation" Version="11.11.0" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.6.0.1" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="System.Text.Json" Version="8.0.0" />
</ItemGroup>
<Choose>
<When Condition="'$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'netstandard2.0'">
<ItemGroup>
<PackageReference Include="System.Text.Json" Version="6.0.11" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<PackageReference Include="System.Text.Json" Version="9.0.1" />
</ItemGroup>
</Otherwise>
</Choose>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="System.Text.Json" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">

<PackageReference Include="System.Text.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0"/>

</ItemGroup>

</Project>
16 changes: 8 additions & 8 deletions test/RulesEngine.UnitTest/RulesEngine.UnitTest.csproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\signing\RulesEngine-publicKey.snk</AssemblyOriginatorKeyFile>
<DelaySign>True</DelaySign>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoFixture" Version="4.18.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
<PackageReference Include="xunit" Version="2.6.5" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<PackageReference Include="AutoFixture" Version="5.0.0-preview0012" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="System.Text.Json" Version="9.0.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Loading