You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was successfully able to hack around it, by adding the following to my enum, providing the hints to the IL to prevent it optimizing away the info needed to perform reflection.
Thought It would be beneficial to set these options in the source if possible, so the warnings are prevented, or at least open an issue for others to reference if they're in a similar situation.
Perhaps its also worth giving some consideration to the feasiblity of whether the use of reflection could be avoided entirely/optionally.
Could derived classes provide their own implementation of GetAllOptions, or perhaps theres another approach of handling the 'discoverability' of available options?
Could it be as simple as being 'registered' into the _enumOptions collection when being constructed?
The text was updated successfully, but these errors were encountered:
Firstly, let me open with my thanks for this library, I've only recently discovered it, but wish I'd found it earlier! 😄
I've had a minor issue in the project I'm working on, which is being compiled for native AOT. The following warning is displayed in VS:
Assembly 'Ardalis.SmartEnum' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries
And it didn't work as expected, due to my smart enum not being able to obtain values using the
TryFromValue
method.I had a quick look at the source, and I suspected this was due to the use of reflection:
SmartEnum/src/SmartEnum/SmartEnum.cs
Lines 70 to 79 in 0eae38b
SmartEnum/src/SmartEnum/TypeExtensions.cs
Lines 10 to 16 in 0eae38b
I was successfully able to hack around it, by adding the following to my enum, providing the hints to the IL to prevent it optimizing away the info needed to perform reflection.
Thought It would be beneficial to set these options in the source if possible, so the warnings are prevented, or at least open an issue for others to reference if they're in a similar situation.
Perhaps its also worth giving some consideration to the feasiblity of whether the use of reflection could be avoided entirely/optionally.
Could derived classes provide their own implementation of GetAllOptions, or perhaps theres another approach of handling the 'discoverability' of available options?
Could it be as simple as being 'registered' into the _enumOptions collection when being constructed?
The text was updated successfully, but these errors were encountered: