CRUDTools 1.1.3-alpha-gf4ceba3e5b
CRUD Tools
CRUD Tools adds a few features to help deal with JSON input and output in an ASP.NET API:
Option Type
The option type is meant to help differentiate between these 3 JSON inputs:
{ username: "marc.weber" }
{ username: null }
{ }
Normally ASP.NET does not have a way to tell the second two apart, but by using an Option<string?> username
in your model, the second input will result in:
username.HasValue => true
username.Value => null
And the third input will result in:
username.HasValue => false
username.Value => (error)
This can help with /Update
endpoints, where { username: null }
would set the username to null but { }
would leave username unchanged.
Type Converter
TypeConverter.ConvertTypeByPropertyNames
just copies all variables from one model to another model based on the variable name, casting if the variable in the target model is a different type. If it cannot cast, an error will be thrown.
TypeConverter.ConvertOptionTypeByPropertyNames
does the same thing, but if the source type is an Option<>
, the variable is not copied if source_var.HasValue
is false.
No packages depend on CRUDTools.
.NET 6.0
- Newtonsoft.Json (>= 13.0.3)
Version | Downloads | Last updated |
---|---|---|
1.1.3-alpha-gf4ceba3e5b | 5 | 05/04/2024 |
1.1.2-alpha-gbca5c0f0c1 | 9 | 02/16/2024 |
1.1.1-alpha-gc395ba60d7 | 0 | 02/16/2024 |
1.0.0 | 1 | 02/16/2024 |