23 lines
775 B
C#
23 lines
775 B
C#
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);
|
|
}
|
|
}
|
|
}
|