vendredi 30 octobre 2015

Efficient way to access a property of a class by the string name

I want access to a property value by its name. The only way i know it's by reflection with a code like this:

 public static object GetPropValue(object src, string propName)
 {
     return src.GetType().GetProperty(propName).GetValue(src, null);
 }

Are there others ways to do it (using ex. codegen, etc.)?





Aucun commentaire:

Enregistrer un commentaire