I am trying to get the data type of a property dynamically in my app. I have the following line of code using the name of the backing variable for the property to get the type and it works correctly.
var tobj_Type = this.GetType().GetField("ii_ServerPort", BindingFlags.Public | BindingFlags.Instance).GetValue(this).GetType();
In this line of code, I attempt to use the name of the property to try to get the type.
var tobj_PropertyType = this.GetType().GetField("ServerPort", BindingFlags.Public | BindingFlags.Instance).GetValue(this).GetType();
It fails with the following error: Object reference not set to an instance of an object.
Any idea how I can use the property name here instead of the backing variable?
Aucun commentaire:
Enregistrer un commentaire