0

I have this base class:

public class Result<T>
{
    public T Object { get; set; }
}

and this derived type:

public class OkResult<T> : Result<T>
{

}

that has this dervied type:

public class Ok : OkResult<Object>
{
}

To have a method with this signature as return:

        Result<Guid> Test()
        {
            return new OkResult<Guid>(Guid.NewGuid());
        }

That I can use like this:

var test = Test();
if(test is Ok)
{ 
do something...
}

and also this (if you do the same with error)

var test = Test();
if(test is Error)
{ 
do something...
}

My problem is that it does not work for both structs and objects eventhough struct inherits from object, only for objects. I cannot cast a Result to Ok. Eventhough Ok inherits from OkResult

Is there any solution to this? I just want to check that what ever Im getting back is Ok.

Erik83
  • 539
  • 3
  • 5
  • 19

0 Answers0