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);
|
2021-05-17 14:01:06 +02:00
|
|
|
|
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();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|