Luca | LeCarbonator
Luca | LeCarbonator
Explore posts from servers
CC#
Created by Luca | LeCarbonator on 11/18/2024 in #help
✅ Binding Nested values in RequestBody to Model
I seem to have find a way to do it in the model binder:
public class FooBinder : IModelBinder
{
public async Task BindModelAsync(ModelBindingContext bindingContext)
{
if (bindingContext.ModelType != typeof(Foo))
{
bindingContext.Result = ModelBindingResult.Failed();
return;
}

var readResult = await bindingContext.HttpContext.Request.BodyReader.ReadAsync();
var content = Encoding.UTF8.GetString(readResult.Buffer);

if (content == null)
{
bindingContext.Result = ModelBindingResult.Failed();
return;
}

var jo = JObject.Parse(content);

// Set all properties with a [JsonProperty] attribute attached
Foo? output = jo.ToObject<Foo>();

if (output == null)
{
bindingContext.Result = ModelBindingResult.Failed();
return;
}

output.BarProp = (string)jo.SelectToken("some.nested.property.from.json")!;

bindingContext.Result = ModelBindingResult.Success(output);
return;
}
}
public class FooBinder : IModelBinder
{
public async Task BindModelAsync(ModelBindingContext bindingContext)
{
if (bindingContext.ModelType != typeof(Foo))
{
bindingContext.Result = ModelBindingResult.Failed();
return;
}

var readResult = await bindingContext.HttpContext.Request.BodyReader.ReadAsync();
var content = Encoding.UTF8.GetString(readResult.Buffer);

if (content == null)
{
bindingContext.Result = ModelBindingResult.Failed();
return;
}

var jo = JObject.Parse(content);

// Set all properties with a [JsonProperty] attribute attached
Foo? output = jo.ToObject<Foo>();

if (output == null)
{
bindingContext.Result = ModelBindingResult.Failed();
return;
}

output.BarProp = (string)jo.SelectToken("some.nested.property.from.json")!;

bindingContext.Result = ModelBindingResult.Success(output);
return;
}
}
5 replies
CC#
Created by Luca | LeCarbonator on 11/18/2024 in #help
✅ Binding Nested values in RequestBody to Model
Is there another way to obtain it other than bindingContext.HttpContext.Request.BodyReader?
5 replies
CC#
Created by Luca | LeCarbonator on 11/18/2024 in #help
✅ Binding Nested values in RequestBody to Model
it enforces the read to be async, but IModelBuilder throws an error even though it's async
'CollectionBinder' does not implement interface member 'IModelBinder.BindModelAsync(ModelBindingContext)'. 'CollectionBinder.BindModelAsync(ModelBindingContext)' cannot implement 'IModelBinder.BindModelAsync(ModelBindingContext)' because it does not have the matching return type of 'Task'.
'CollectionBinder' does not implement interface member 'IModelBinder.BindModelAsync(ModelBindingContext)'. 'CollectionBinder.BindModelAsync(ModelBindingContext)' cannot implement 'IModelBinder.BindModelAsync(ModelBindingContext)' because it does not have the matching return type of 'Task'.
5 replies
CC#
Created by Luca | LeCarbonator on 11/18/2024 in #help
✅ Binding Nested values in RequestBody to Model
It looks like Model Binding is the way to go, but getting the request body's text is more difficult than I thought
5 replies
CC#
Created by Luca | LeCarbonator on 11/15/2024 in #help
Specifying 4xx Details
I‘m curious how the default formatting works if I don‘t pass anything to the function It doesn‘t seem editable on its own, but perhaps I can manually create it and then pass it as parameter
8 replies
CC#
Created by Luca | LeCarbonator on 11/15/2024 in #help
Specifying 4xx Details
maybe net9 soon if the changes are related to 4xx error handling as was mentioned before
8 replies
CC#
Created by Luca | LeCarbonator on 11/15/2024 in #help
Specifying 4xx Details
I haven‘t clarified it yet, you‘re right. My target is net8
8 replies
CC#
Created by Luca | LeCarbonator on 11/15/2024 in #help
Specifying 4xx Details
Oh, interesting! I'll take a look. Also thanks for the video reference
8 replies
CC#
Created by Luca | LeCarbonator on 11/13/2024 in #help
✅ Is it possible to access a Controller's URI at runtime?
:HmmNotes: sounds like a plan. These keywords should be enough to solve the post. Do I just mark it with :greencheck: ?
20 replies
CC#
Created by Luca | LeCarbonator on 11/13/2024 in #help
✅ Is it possible to access a Controller's URI at runtime?
thanks for the advice
20 replies
CC#
Created by Luca | LeCarbonator on 11/13/2024 in #help
✅ Is it possible to access a Controller's URI at runtime?
hmm, I see. I'll read up on the HttpContext then
20 replies
CC#
Created by Luca | LeCarbonator on 11/13/2024 in #help
✅ Is it possible to access a Controller's URI at runtime?
Either one is of help, since the href should already be a filled out URL At least I don't expect to change my endpoints constantly, so that is okay to be hardcoded for this size of a project
20 replies
DIAdiscord.js - Imagine an app
Created by AgEnT007 on 4/21/2024 in #djs-questions
help
this also immediately attempts to get the member instead of a User object. If this returns null, then the provided user does not exist in the server
13 replies
DIAdiscord.js - Imagine an app
Created by AgEnT007 on 4/21/2024 in #djs-questions
help
there you go, use this boolean to check first. You would have received help a lot sooner if you explained that in your post or post title
13 replies
DIAdiscord.js - Imagine an app
Created by AgEnT007 on 4/21/2024 in #djs-questions
help
* Explain what exactly your issue is. * Post the full error stack trace, not just the top part!
13 replies
DIAdiscord.js - Imagine an app
Created by AgEnT007 on 4/21/2024 in #djs-questions
help
and what error is thrown?
13 replies
DIAdiscord.js - Imagine an app
Created by [+] blocked on 4/17/2024 in #djs-questions
I need Help with my Ticket System for Discord
#rules 5, please respect it. I have no interest in having a DM conversation with you
14 replies
DIAdiscord.js - Imagine an app
Created by [+] blocked on 4/17/2024 in #djs-questions
I need Help with my Ticket System for Discord
no.
14 replies
DIAdiscord.js - Imagine an app
Created by [+] blocked on 4/17/2024 in #djs-questions
I need Help with my Ticket System for Discord
#resources provides plenty of stuff to get started on JavaScript, in case you need it
14 replies
DIAdiscord.js - Imagine an app
Created by [+] blocked on 4/17/2024 in #djs-questions
I need Help with my Ticket System for Discord
it makes it difficult for people to help you, and nobody will just do the work for you.
14 replies