Get type using reflection

后端 未结 3 1194
日久生厌
日久生厌 2021-01-04 23:39

I am trying get type of property of my class by using of reflection but its returning my only RuntimePropertyInfo - as a name of a type.

I have object MyObject actua

3条回答
  •  花落未央
    2021-01-04 23:56

    You're getting the type of the PropertyInfo object getProperty() returns. Try

    string typeName = actualData.getType().getProperty("Item").PropertyType.Name;
    

    If you want the type of the value currently assigned to the object via the PropertyInfo object, you could call:

    string typeName = actualData.getType().getProperty("Item").GetValue(actualData, null).GetType().Name;
    

    But in that case you could also simply call:

    string typeName = actualData.Item.GetType().Name;
    

提交回复
热议问题