Files
BeWoPlaner/Shared/Extensions/ObjectExtensions.cs

29 lines
1.0 KiB
C#
Raw Normal View History

2016-06-27 01:45:38 +02:00
using System.Reflection;
namespace BS.Shared.Extensions
{
public static class ObjectExtensions
{
public static bool EqualsNullCheck(this object pObject, object otherObject)
{
return pObject == null ? otherObject == null : pObject.Equals(otherObject);
}
public static object GetPropertyValue(this object pObject, string pPropertyName)
{
PropertyInfo pPropInfo = pObject.GetType().GetProperty(pPropertyName);
return pPropInfo == null ? null : pPropInfo.GetValue(pObject, null);
}
public static void SetPropertyValue(this object pObject, string pPropertyName, object value)
{
PropertyInfo pPropInfo = pObject.GetType().GetProperty(pPropertyName);
pPropInfo?.SetValue(pObject, value, null);
2016-06-27 01:45:38 +02:00
}
public static string ToStringNullCheck(this object pObject)
{
return pObject == null ? string.Empty : pObject.ToString();
}
}
}