Skip to content
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
12 changes: 12 additions & 0 deletions src/ExCSS/ExCSS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@
-->
</PropertyGroup>

<!-- Trimming parameters -->
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">
<IsTrimmable>true</IsTrimmable>
<SuppressTrimAnalysisWarnings>false</SuppressTrimAnalysisWarnings>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
</PropertyGroup>
<!-- AOT parameters -->
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
<IsAotCompatible>true</IsAotCompatible>
<EnableAotAnalyzer>true</EnableAotAnalyzer>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' != ''">
<LangVersion>9.0</LangVersion>
</PropertyGroup>
Expand Down
7 changes: 6 additions & 1 deletion src/ExCSS/Extensions/PortableExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;

Expand All @@ -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();
}
Expand Down
32 changes: 16 additions & 16 deletions src/ExCSS/Factories/AttributeSelectorFactory.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
using System;
using System.Collections.Generic;

namespace ExCSS
{
public sealed class AttributeSelectorFactory
{
private static readonly Lazy<AttributeSelectorFactory> Lazy = new(() => new AttributeSelectorFactory());

private readonly Dictionary<string, Type> _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()
{
}
Expand All @@ -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);
Expand Down