Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TEnum[] to List<TEnum> for webassembly compatibility issue in .net 9 #557

Merged
merged 2 commits into from
Nov 19, 2024
Merged
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
8 changes: 4 additions & 4 deletions src/SmartEnum/SmartEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public abstract class SmartEnum<TEnum, TValue> :
where TEnum : SmartEnum<TEnum, TValue>
where TValue : IEquatable<TValue>, IComparable<TValue>
{
static readonly Lazy<TEnum[]> _enumOptions =
new Lazy<TEnum[]>(GetAllOptions, LazyThreadSafetyMode.ExecutionAndPublication);
static readonly Lazy<List<TEnum>> _enumOptions =
new Lazy<List<TEnum>>(GetAllOptions, LazyThreadSafetyMode.ExecutionAndPublication);

static readonly Lazy<Dictionary<string, TEnum>> _fromName =
new Lazy<Dictionary<string, TEnum>>(() => _enumOptions.Value.ToDictionary(item => item.Name));
Expand All @@ -67,15 +67,15 @@ public abstract class SmartEnum<TEnum, TValue> :
return dictionary;
});

private static TEnum[] GetAllOptions()
private static List<TEnum> GetAllOptions()
{
Type baseType = typeof(TEnum);
return Assembly.GetAssembly(baseType)
.GetTypes()
.Where(t => baseType.IsAssignableFrom(t))
.SelectMany(t => t.GetFieldsOfType<TEnum>())
.OrderBy(t => t.Name)
.ToArray();
.ToList();
}

private static IEqualityComparer<TValue> GetValueComparer()
Expand Down