I have a Redis subscription in a channel that returns me two type of objects
one is the success that returns me this:
public class Success {
public string Token {get; set;}
public object Message {get; set;}
}
and another one for error
public class Error {
public string ErrorMessage {get; set;}
public string Name {get; set;}
}
My redis subscriptions on message code is this:
subscription.OnMessage = (channel, msg) =>
{
var success = JsonConvert.DeserializeObject<Success>(msg);
// do the things with success
};
but i dont know when the error will be returned, so i need to deserialize to the Success or to the Error model based on the properties, something like this:
var successOrError = JsonConvert.DeserializeObject<Either<Success, Error>>(msg);
is this possible ? or there is another way to do this