I have a generic Type as follows
public class TestGeneric
{
public T Data { get; set; }
public TestGeneric(T data)
{
this.Data =
You need to know the closed type of a generic class before you can access its generic members. The use of TestGeneric<> gives you the open type definition, which cannot be invoked without specifying the generic arguments.
The simplest way for you to get the value of the property is to reflect on the closed type in use directly:
public static void Main()
{
object myObject = new TestGeneric("test"); // or from another source
var type = myObject.GetType();
if (IsSubclassOfRawGeneric(typeof(TestGeneric<>), type))
{
var dataProperty = type.GetProperty("Data");
object data = dataProperty.GetValue(myObject, new object[] { });
}
}