Wednesday, December 17, 2014

Get/Set property value in an object instance using reflection

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

public static object SetPropValue(T src, string propName, object value)
{
  return src.GetType().GetProperty(propName).SetValue(src, value);
}

No comments:

Post a Comment