I am trying to see if an object is of a specified type, but that type receives a generic, and I don't know how to do this check. For example let's say I have a class:
public class MyClass<T> where T : class
{
private T Prop { get; set; }
}
and an empty class:
public class A : Object
{
}
Instantiating an object of MyClass
with given type of A
and comparing this object type to MyClass
but which receives a type of Object
will always return false, like in the following case:
class Program
{
static void Main(string[] args)
{
var test = new MyClass<A>();
bool result = test is MyClass<Object>;
Console.WriteLine(result.ToString());
}
}
Here the type of A
is Object
, but the result will be always false.
In this case I just want to check if the object test
has the type of MyClass
, whatever T
will be. How am I supposed to do this?