From 5dd85b4d3479cf0db07909c80edabad60bce757e Mon Sep 17 00:00:00 2001 From: Frank Alvarez Date: Thu, 30 Jan 2025 00:18:34 -0500 Subject: [PATCH] Update projects for .NET 8.0 and 9.0 support (#648) * Update projects for .NET 8.0 and 9.0 support - Added BenchmarkDotNet attributes in Program.cs for .NET 8.0 and 9.0. - Updated RulesEngineBenchmark.csproj to target .NET 8.0 and 9.0; upgraded BenchmarkDotNet to 0.14.0. - Modified DemoApp.EFDataExample.csproj to target .NET 8.0 and 9.0; upgraded EF Core packages to 9.0.1. - Changed DemoApp.csproj to target .NET 8.0 and 9.0, preserving project references and workflow files. - Updated global.json to specify SDK version 9.0.0. - Modified RulesEngine.csproj to target .NET 9.0 and updated package references, including System.Text.Json. - Updated RulesEngine.UnitTest.csproj to target .NET 8.0 and 9.0; upgraded testing libraries and System.Text.Json. * re-introduced net6.0 support * update AutoFixture to fix vulnerabilities * add JsonElement support to fix error in the DemoApp --------- Co-authored-by: Purunjay Bhal --- benchmark/RulesEngineBenchmark/Program.cs | 6 ++- .../RulesEngineBenchmark.csproj | 8 +-- .../DemoApp.EFDataExample.csproj | 6 +-- demo/DemoApp/DemoApp.csproj | 4 +- global.json | 2 +- src/RulesEngine/HelperFunctions/Utils.cs | 54 ++++++++++--------- src/RulesEngine/RulesEngine.csproj | 39 +++++++------- .../RulesEngine.UnitTest.csproj | 16 +++--- 8 files changed, 73 insertions(+), 62 deletions(-) diff --git a/benchmark/RulesEngineBenchmark/Program.cs b/benchmark/RulesEngineBenchmark/Program.cs index e8aeb7a7..8f332795 100644 --- a/benchmark/RulesEngineBenchmark/Program.cs +++ b/benchmark/RulesEngineBenchmark/Program.cs @@ -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; diff --git a/benchmark/RulesEngineBenchmark/RulesEngineBenchmark.csproj b/benchmark/RulesEngineBenchmark/RulesEngineBenchmark.csproj index f6e806ac..0eb2c7bf 100644 --- a/benchmark/RulesEngineBenchmark/RulesEngineBenchmark.csproj +++ b/benchmark/RulesEngineBenchmark/RulesEngineBenchmark.csproj @@ -2,16 +2,16 @@ Exe - net8.0 + net6.0;net8.0;net9.0 - - + + - + diff --git a/demo/DemoApp.EFDataExample/DemoApp.EFDataExample.csproj b/demo/DemoApp.EFDataExample/DemoApp.EFDataExample.csproj index 210fdad8..40577574 100644 --- a/demo/DemoApp.EFDataExample/DemoApp.EFDataExample.csproj +++ b/demo/DemoApp.EFDataExample/DemoApp.EFDataExample.csproj @@ -1,14 +1,14 @@ - net8.0 + net8.0;net9.0 DemoApp.EFDataExample DemoApp.EFDataExample - - + + diff --git a/demo/DemoApp/DemoApp.csproj b/demo/DemoApp/DemoApp.csproj index 626fa62c..83f0d8a7 100644 --- a/demo/DemoApp/DemoApp.csproj +++ b/demo/DemoApp/DemoApp.csproj @@ -2,7 +2,7 @@ Exe - net8.0 + net8.0;net9.0 DemoApp.Program @@ -10,7 +10,7 @@ - + PreserveNewest diff --git a/global.json b/global.json index da113e4c..90b30429 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "8.0.0", + "version": "9.0.0", "rollForward": "latestFeature", "allowPrerelease": false } diff --git a/src/RulesEngine/HelperFunctions/Utils.cs b/src/RulesEngine/HelperFunctions/Utils.cs index 4ae9262a..05df93dd 100644 --- a/src/RulesEngine/HelperFunctions/Utils.cs +++ b/src/RulesEngine/HelperFunctions/Utils.cs @@ -26,39 +26,46 @@ public static object GetTypedObject(dynamic input) } public static Type CreateAbstractClassType(dynamic input) { - List props = new List(); + List 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)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); - else - { - var internalType = CreateAbstractClassType(((IList)expando.Value)[0]); - value = new List().Cast(internalType).ToList(internalType).GetType(); - } - + value = typeof(List); } else { - value = CreateAbstractClassType(expando.Value); + var internalType = CreateAbstractClassType(list[0]); + value = new List().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); @@ -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)input) + foreach (var expando in expandoObject) { if (typeProps.ContainsKey(expando.Key) && expando.Value != null && (expando.Value.GetType().Name != "DBNull" || expando.Value != DBNull.Value)) @@ -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().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; diff --git a/src/RulesEngine/RulesEngine.csproj b/src/RulesEngine/RulesEngine.csproj index e2cc7557..5a9bb266 100644 --- a/src/RulesEngine/RulesEngine.csproj +++ b/src/RulesEngine/RulesEngine.csproj @@ -1,15 +1,16 @@ - + - net8.0;net6.0;netstandard2.0 + net6.0;net8.0;net9.0;netstandard2.0 + 13.0 5.0.4 Copyright (c) Microsoft Corporation. LICENSE https://github.com/microsoft/RulesEngine Abbas Cyclewala 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. - https://github.com/microsoft/RulesEngine/blob/main/CHANGELOG.md - BRE, Rules Engine, Abstraction + https://github.com/microsoft/RulesEngine/blob/main/CHANGELOG.md + BRE, Rules Engine, Abstraction README.md @@ -33,27 +34,27 @@ - - - - - + + + - - - + + + + + + + + + + + + - - - - - - - diff --git a/test/RulesEngine.UnitTest/RulesEngine.UnitTest.csproj b/test/RulesEngine.UnitTest/RulesEngine.UnitTest.csproj index 23de56b6..d8878314 100644 --- a/test/RulesEngine.UnitTest/RulesEngine.UnitTest.csproj +++ b/test/RulesEngine.UnitTest/RulesEngine.UnitTest.csproj @@ -1,21 +1,21 @@ - net8.0 + net6.0;net8.0;net9.0 True ..\..\signing\RulesEngine-publicKey.snk True - - - - - - + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive