Skip to content

Commit c97e84d

Browse files
authored
Merge pull request #188 from maxkatz6/aot-compat
Add IsTrimmable and IsAotCompatible project attributes
2 parents b0e2f46 + 96c1315 commit c97e84d

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

src/ExCSS/ExCSS.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@
3131
-->
3232
</PropertyGroup>
3333

34+
<!-- Trimming parameters -->
35+
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">
36+
<IsTrimmable>true</IsTrimmable>
37+
<SuppressTrimAnalysisWarnings>false</SuppressTrimAnalysisWarnings>
38+
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
39+
</PropertyGroup>
40+
<!-- AOT parameters -->
41+
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
42+
<IsAotCompatible>true</IsAotCompatible>
43+
<EnableAotAnalyzer>true</EnableAotAnalyzer>
44+
</PropertyGroup>
45+
3446
<PropertyGroup Condition="'$(TargetFramework)' != ''">
3547
<LangVersion>9.0</LangVersion>
3648
</PropertyGroup>

src/ExCSS/Extensions/PortableExtensions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics.CodeAnalysis;
23
using System.Linq;
34
using System.Reflection;
45

@@ -13,7 +14,11 @@ public static string ConvertFromUtf32(this int utf32)
1314
return char.ConvertFromUtf32(utf32);
1415
}
1516

16-
public static PropertyInfo[] GetProperties(this Type type)
17+
public static PropertyInfo[] GetProperties(
18+
#if NET6_0_OR_GREATER
19+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties)]
20+
#endif
21+
this Type type)
1722
{
1823
return type.GetRuntimeProperties().ToArray();
1924
}

src/ExCSS/Factories/AttributeSelectorFactory.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11
using System;
2-
using System.Collections.Generic;
32

43
namespace ExCSS
54
{
65
public sealed class AttributeSelectorFactory
76
{
87
private static readonly Lazy<AttributeSelectorFactory> Lazy = new(() => new AttributeSelectorFactory());
98

10-
private readonly Dictionary<string, Type> _types = new()
11-
{
12-
{ Combinators.Exactly, typeof(AttrMatchSelector) },
13-
{ Combinators.InList, typeof(AttrListSelector) },
14-
{ Combinators.InToken, typeof(AttrHyphenSelector) },
15-
{ Combinators.Begins, typeof(AttrBeginsSelector) },
16-
{ Combinators.Ends, typeof(AttrEndsSelector) },
17-
{ Combinators.InText, typeof(AttrContainsSelector) },
18-
{ Combinators.Unlike, typeof(AttrNotMatchSelector) },
19-
};
20-
219
private AttributeSelectorFactory()
2210
{
2311
}
@@ -34,11 +22,23 @@ public IAttrSelector Create(string combinator, string match, string value, strin
3422
_ = AttributeSelectorFactory.FormMatch(prefix, match);
3523
}
3624

37-
return _types.TryGetValue(combinator, out var type)
38-
? (IAttrSelector)Activator.CreateInstance(type, name, value)
39-
: new AttrAvailableSelector(name, value);
25+
if (combinator == Combinators.Exactly)
26+
return new AttrMatchSelector(name, value);
27+
if (combinator == Combinators.InList)
28+
return new AttrListSelector(name, value);
29+
if (combinator == Combinators.InToken)
30+
return new AttrHyphenSelector(name, value);
31+
if (combinator == Combinators.Begins)
32+
return new AttrBeginsSelector(name, value);
33+
if (combinator == Combinators.Ends)
34+
return new AttrEndsSelector(name, value);
35+
if (combinator == Combinators.InText)
36+
return new AttrContainsSelector(name, value);
37+
if (combinator == Combinators.Unlike)
38+
return new AttrNotMatchSelector(name, value);
39+
return new AttrAvailableSelector(name, value);
4040
}
41-
41+
4242
private static string FormFront(string prefix, string match)
4343
{
4444
return string.Concat(prefix, Combinators.Pipe, match);

0 commit comments

Comments
 (0)