Skip to content

Commit

Permalink
Improved AOT compatibility of HtmlTagId and HtmlAttributeId extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
jstedfast committed Nov 29, 2024
1 parent 640dec6 commit f9c53d5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
11 changes: 7 additions & 4 deletions MimeKit/Text/HtmlAttributeId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -694,15 +694,18 @@ public static class HtmlAttributeIdExtensions
static HtmlAttributeIdExtensions ()
{
#if NET8_0_OR_GREATER
var values = Enum.GetValues<HtmlAttributeId> ();
var values = Enum.GetValuesAsUnderlyingType<HtmlAttributeId> ();
#else
var values = (HtmlAttributeId[]) Enum.GetValues (typeof (HtmlAttributeId));
var values = Enum.GetValues (typeof (HtmlAttributeId));
#endif

IdMapping = new Dictionary<string, HtmlAttributeId> (values.Length - 1, MimeUtils.OrdinalIgnoreCase);

for (int i = 1; i < values.Length; i++)
IdMapping.Add (values[i].ToAttributeName (), values[i]);
for (int i = 1; i < values.Length; i++) {
var value = (HtmlAttributeId) values.GetValue (i);

IdMapping.Add (value.ToAttributeName (), value);
}
}

/// <summary>
Expand Down
11 changes: 7 additions & 4 deletions MimeKit/Text/HtmlTagId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -865,15 +865,18 @@ public static class HtmlTagIdExtensions
static HtmlTagIdExtensions ()
{
#if NET8_0_OR_GREATER
var values = Enum.GetValues<HtmlTagId> ();
var values = Enum.GetValuesAsUnderlyingType<HtmlTagId> ();
#else
var values = (HtmlTagId[]) Enum.GetValues (typeof (HtmlTagId));
var values = Enum.GetValues (typeof (HtmlTagId));
#endif

IdMapping = new Dictionary<string, HtmlTagId> (values.Length - 1, MimeUtils.OrdinalIgnoreCase);

for (int i = 1; i < values.Length; i++)
IdMapping.Add (values[i].ToHtmlTagName (), values[i]);
for (int i = 1; i < values.Length; i++) {
var value = (HtmlTagId) values.GetValue (i);

IdMapping.Add (value.ToHtmlTagName (), value);
}
}

/// <summary>
Expand Down

0 comments on commit f9c53d5

Please sign in to comment.