public static object GetValue(this MemberInfo member, object source)
{
var fieldInfo = member as FieldInfo;
if (fieldInfo != null)
{
var field = DelegateFactory.CreateGet(fieldInfo);
return field.Invoke(source);
}
var propertyInfo = (PropertyInfo) member;
if (!propertyInfo.CanRead)
{
if (propertyInfo.PropertyType.IsValueType)
{
return Activator.CreateInstance(propertyInfo.PropertyType);
}
return null;
}
var property = DelegateFactory.CreateGet(propertyInfo);
return property.Invoke(source);
}