using System.Reflection; namespace Chrosey.Extensions { public static class BasicExtensions { public static bool HasProperty(this object me, string propertyName) { return me.GetType().GetProperty(propertyName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance) != null; } public static object GetPropertyValue(this object me, string propertyName) { if (!me.HasProperty(propertyName)) throw new NotFoundException("Property not found " + propertyName); return me .GetType() .GetProperty(propertyName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance) .GetValue(me, null); } } }