Comments (3)
Sorry this doesn't directly answer your question, but I've managed to find a workaround by making my [FromQuery] object use a string type... It's not as clean, but it does the job.
on my Controller:
public async Task<IActionResult> GetPepVariants([FromQuery] GetAdminPepVariantsQuery request) =>
The request type:
public class GetAdminPepVariantsQuery
{
...
public string? PepType { get; set; }
...
}
The EF query (or any other use)
query = query.Where(p => p.PepType == PepType.FromName(request.PepType, true));
from smartenum.
@laska-u, when the data is not really a JSON coming from a request body, the JsonConverters are not executed. I just encountered the same issue, and there are two options that worked for me:
- Use a custom TypeConverter as described in the Microsoft docs. Their example uses a GeoPoint type, but in our example with SmartEnums, you would just convert by calling
FromValue(s)
. - If you are using .NET 7, you can just add a
TryParse
implementation in your SmartEnum, and the framework will call it. Here is an example of that in the release notes of .NET 7 preview 3.
You can also use a custom model binder, but I didn't try that option as it's not needed.
@ardalis, should any of these options be added into the library? I'm open on contributing if you agree.
from smartenum.
@miroslavgrozdanovski Sure, that would be great. I probably need to improve the docs for SmartEnum some time as well, to cover things like this that aren't necessarily "in the box"...
from smartenum.
Related Issues (20)
- SmartFlagEnum does not support values larger than int.MaxValue HOT 1
- Need simple method to get single int value from existing IEnumerable<MyFlagEnum>. HOT 5
- Ordering the values
- Can/should SmartEnum implement the non-generic IComparable interface?
- SmartEnumStringComparer not included in 7.0.0 version HOT 2
- Add a ValidationAttribute to Validate Model Property Against SmartEnum Names
- ushort error in SmartFlagEnumValueConverter HOT 1
- For the README.md I found out that the path for TestEnum.cs is broken HOT 1
- Add Description attribute HOT 1
- Please Release Version for .NET 8.0 HOT 3
- Are you open to a PR for a nullable `Name`? HOT 2
- Add a way to enumerate over the List to prevent allocation every time List is called HOT 2
- Support for a default enum value?
- Add support for NRT HOT 1
- Revert PR 412 and remove support for null values. HOT 1
- eliminate explicit dependency for STJ on newer frameworks HOT 7
- Use canonical null checks.
- Json Serializer
- Avoid creating a new list on SmartEnum.List HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from smartenum.