From d9258c2a39aa2aa82bc6aedd1ef269a0fcceb932 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Sun, 20 Jul 2025 17:14:38 +0200 Subject: [PATCH 1/3] Add trimming/aot propertys in net6.0+ targets --- src/ExCSS/ExCSS.csproj | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ExCSS/ExCSS.csproj b/src/ExCSS/ExCSS.csproj index 8967ff2..8ebfc3c 100644 --- a/src/ExCSS/ExCSS.csproj +++ b/src/ExCSS/ExCSS.csproj @@ -31,6 +31,14 @@ --> + + + true + true + false + true + + 9.0 From c497ca7e600f590f6252c381843392fb9c050202 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Sun, 20 Jul 2025 17:15:28 +0200 Subject: [PATCH 2/3] Remove reflection usage in AttributeSelectorFactory --- src/ExCSS/Extensions/PortableExtensions.cs | 7 +++- .../Factories/AttributeSelectorFactory.cs | 32 +++++++++---------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/ExCSS/Extensions/PortableExtensions.cs b/src/ExCSS/Extensions/PortableExtensions.cs index c90f169..a5f2740 100644 --- a/src/ExCSS/Extensions/PortableExtensions.cs +++ b/src/ExCSS/Extensions/PortableExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; @@ -13,7 +14,11 @@ public static string ConvertFromUtf32(this int utf32) return char.ConvertFromUtf32(utf32); } - public static PropertyInfo[] GetProperties(this Type type) + public static PropertyInfo[] GetProperties( +#if NET6_0_OR_GREATER + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties)] +#endif + this Type type) { return type.GetRuntimeProperties().ToArray(); } diff --git a/src/ExCSS/Factories/AttributeSelectorFactory.cs b/src/ExCSS/Factories/AttributeSelectorFactory.cs index 21a9eb0..0c72de5 100644 --- a/src/ExCSS/Factories/AttributeSelectorFactory.cs +++ b/src/ExCSS/Factories/AttributeSelectorFactory.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; namespace ExCSS { @@ -7,17 +6,6 @@ public sealed class AttributeSelectorFactory { private static readonly Lazy Lazy = new(() => new AttributeSelectorFactory()); - private readonly Dictionary _types = new() - { - { Combinators.Exactly, typeof(AttrMatchSelector) }, - { Combinators.InList, typeof(AttrListSelector) }, - { Combinators.InToken, typeof(AttrHyphenSelector) }, - { Combinators.Begins, typeof(AttrBeginsSelector) }, - { Combinators.Ends, typeof(AttrEndsSelector) }, - { Combinators.InText, typeof(AttrContainsSelector) }, - { Combinators.Unlike, typeof(AttrNotMatchSelector) }, - }; - private AttributeSelectorFactory() { } @@ -34,11 +22,23 @@ public IAttrSelector Create(string combinator, string match, string value, strin _ = AttributeSelectorFactory.FormMatch(prefix, match); } - return _types.TryGetValue(combinator, out var type) - ? (IAttrSelector)Activator.CreateInstance(type, name, value) - : new AttrAvailableSelector(name, value); + if (combinator == Combinators.Exactly) + return new AttrMatchSelector(name, value); + if (combinator == Combinators.InList) + return new AttrListSelector(name, value); + if (combinator == Combinators.InToken) + return new AttrHyphenSelector(name, value); + if (combinator == Combinators.Begins) + return new AttrBeginsSelector(name, value); + if (combinator == Combinators.Ends) + return new AttrEndsSelector(name, value); + if (combinator == Combinators.InText) + return new AttrContainsSelector(name, value); + if (combinator == Combinators.Unlike) + return new AttrNotMatchSelector(name, value); + return new AttrAvailableSelector(name, value); } - + private static string FormFront(string prefix, string match) { return string.Concat(prefix, Combinators.Pipe, match); From 96c131555551055b71771d9b985f4753f7c34f11 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Sun, 20 Jul 2025 17:22:56 +0200 Subject: [PATCH 3/3] Don't set IsAotCompatible on net6.0 build (not supported there) --- src/ExCSS/ExCSS.csproj | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ExCSS/ExCSS.csproj b/src/ExCSS/ExCSS.csproj index 8ebfc3c..18219af 100644 --- a/src/ExCSS/ExCSS.csproj +++ b/src/ExCSS/ExCSS.csproj @@ -33,11 +33,15 @@ - true true false true + + + true + true + 9.0