I am trying to understand how converting strings to objects works in C#. So I have the following string:
public async Task<String> FunctionReturningReponse() {
var response = "{'ReponseText': 'Some Text'}";
return response
}
Now I created a schema as following:
public class TriggerResponse
{
public string? ReponseText { get; set; } = string.Empty;
}
Can I somehow use this schema to convert my string above to the object of type TriggerReponse so that I can avoid the error in this code:
public class TriggerEmailSendingQueryHandler : IRequestHandler<TriggerEmailSendingQuery, TriggerResponse>
{
private readonly IConfiguration configuration;
public TriggerEmailSendingQueryHandler(IConfiguration configuration)
{
this.configuration = configuration;
}
public async Task<TriggerResponse> Handle(TriggerEmailSendingQuery request, CancellationToken cancellationToken)
{
IConfigurationSection pcConfig = configuration.GetSection(PolicyCenterClient.PC_CONFIG_SECTION);
var triggerResponse = await FunctionReturningReponse();
return triggerResponse;
}
}
Because when I return triggerResponse which is a string returned from the first function I get this error:
Cannot implicitly convert type 'string' to 'Services.Schema.TriggerResponse' [Application]