Struggling with this problem. I have a class that looks like this.
public class Result<T> where T: class, new()
{
public T? Value { get; set; }
}
I’m now trying to cast an object to this class, but I’m not sure how to handle the generic part.
object? funcValue = await GetResponse().Value;
// if (funcValue is Result<object> response) // this doesn't work
if (funcValue.GetType().Name.StartsWith("Result")) // The actual name is Result`1 when debugging
{
var response = (Result<object>) value; // code explodes here but I don't know the generic type to do a proper cast
var res = response.Value; // trying to access the generic type from the Result class.
}