/// <summary> /// Try to get the value of the specified property name from the that.<br /> /// 尝试从对象中获取指定属性名称的值。 /// </summary> /// <param name="that"></param> /// <param name="propertyName"></param> /// <param name="bindingAttr"></param> /// <param name="value"></param> /// <param name="propertyValueGetter"></param> /// <returns></returns> public static bool TryGetPropertyValue(object that, string propertyName, BindingFlags bindingAttr, out object value, IPropertyValueGetter propertyValueGetter) { return(Try.Create(() => propertyValueGetter .SafeRefValue(DefaultPropertyValueGetter.Instance) .Invoke(that.GetType(), that, propertyName, bindingAttr)) .GetSafeValueOut(out value, defaultVal: null) .IsSuccess); }
/// <summary> /// Try to get the value of the specified property name from the that.<br /> /// 尝试从对象中获取指定属性名称的值。 /// </summary> /// <param name="that">Any <see cref="object"/></param> /// <param name="propertyName">Property name in this that</param> /// <param name="propertyValueGetter"></param> /// <param name="value"></param> /// <returns>Value of the specific property in this that</returns> public static bool TryGetPropertyValue <TVal>(object that, string propertyName, IPropertyValueGetter propertyValueGetter, out TVal value) { return(Try.Create(() => propertyValueGetter .SafeRefValue(DefaultPropertyValueGetter.Instance) .Invoke(that.GetType(), that, propertyName) .As <TVal>()) .GetSafeValueOut(out value, defaultVal: default) .IsSuccess); }
/// <summary> /// Get the value of the specified property name from the that.<br /> /// 从对象中获取指定属性名称的值。 /// </summary> /// <param name="that"></param> /// <param name="propertyName"></param> /// <param name="bindingAttr"></param> /// <param name="propertyValueGetter"></param> /// <returns></returns> public static TVal GetPropertyValue <TVal>(object that, string propertyName, BindingFlags bindingAttr, IPropertyValueGetter propertyValueGetter) => propertyValueGetter.SafeRefValue(DefaultPropertyValueGetter.Instance).Invoke(that.GetType(), that, propertyName, bindingAttr).As <TVal>();
/// <summary> /// Get the value of the specified property name from the that.<br /> /// 从对象中获取指定属性名称的值。 /// </summary> /// <param name="that">Any <see cref="object"/></param> /// <param name="propertyName">Property name in this that</param> /// <param name="propertyValueGetter"></param> /// <returns>Value of the specific property in this that</returns> public static object GetPropertyValue(object that, string propertyName, IPropertyValueGetter propertyValueGetter) => propertyValueGetter.SafeRefValue(DefaultPropertyValueGetter.Instance).Invoke(that.GetType(), that, propertyName);