In term the response model is consuming the ArhResponse model, we check 3 type of models of data:
if it is an ArhStringResponse, we create an object of this type, and let the system fill it later, when filling the request and response data
if it is a generic ArhResponse<T> that uses type T, we again create an object of that type, then deserialize the model, and put the result in Result property of that model.
but if the result is a model inheriting the ArhResponse, we deserialize the model and put it directly into the result, in case the response is a empty string for default JSON serializer, the result will (and should) be null.
//It's Normal Deserialization (So we do not need to pre-initialize it)
if (typeof(TResponse) != typeof(ArhStringResponse) &&
!typeof(TResponse).IsSubclassOf(typeof(ArhResponse)))
{
result = DeserializeToObject<TResponse>(responseString);
}
//It's Special Deserialization using RhResponse
else
{
//It contains just string value, And will sits over RhStringResponse (So we need to initialize Model ourselves)
if (typeof(TResponse) == typeof(ArhStringResponse))
{
result = GenerateTResponseRhResponse<TResponse>();
}
//It contains model data, But sits inside RhResponse Model (So we need to initialize Model ourselves)
else if (typeof(TResponse).IsGenericType &&
typeof(TResponse).GetGenericTypeDefinition() == typeof(ArhResponse<>))
{
result = GenerateTResponseRhResponse<TResponse>();
//if Generic Model is String
var genericTypeArgument = typeof(TResponse).GenericTypeArguments[0];
if (genericTypeArgument == typeof(string))
{
SetValueOnProperty(result, nameof(ArhResponse<object>.ResultModel), responseString);
}
//if Generic Model is Object
else
{
// ReSharper disable once PossibleNullReferenceException
object output =
DeserializeToType(responseString, genericTypeArgument);
SetValueOnProperty(result, nameof(ArhResponse<object>.ResultModel), output);
//SetValueOnProperty(result, nameof(RhResponse<object>.ResultModel),
// DeserializeToObject<TResponse>(jsonString);
}
}
//It contains model data, and uses an inherited version of RhResponse (So we do not need to pre-initialize it)
else
{
/*================= ERROR IN HERE =================
result = DeserializeToObject<TResponse>(responseString);
}
}
then later we use the following code to fill the object:
In term the response model is consuming the
ArhResponse
model, we check 3 type of models of data:ArhStringResponse
, we create an object of this type, and let the system fill it later, when filling the request and response dataArhResponse<T>
that uses typeT
, we again create an object of that type, then deserialize the model, and put the result in Result property of that model.ArhResponse
, we deserialize the model and put it directly into the result, in case the response is a empty string for default JSON serializer, the result will (and should) be null.inside:
then later we use the following code to fill the object:
if the result is null, we ignore the response and return the null value directly....
We should either fix this issue inside finally method, or inside the decision making
if
-else
for the data inheriting theArhResponse