示例#1
0
        private KeyValuePair <string, object> TraverseSingleObject(
            object responseNode, FieldSelectorTreeNode selectorNode, string parentSelectorPath)
        {
            string currentPathSelector = FormatSelectorPath(parentSelectorPath, selectorNode);

            IPropertyValueGetter currentProperty =
                _propertyInfoCache.GetOrAdd(
                    currentPathSelector,
                    key => _propertyGetterFactory.CreatePropertyValueGetter(responseNode, selectorNode.MemberName)
                    );

            if (currentProperty == null)
            {
                return(new KeyValuePair <string, object>());
            }

            object value = currentProperty.GetPropertyValue(responseNode);

            if (selectorNode.Children.IsEmpty())
            {
                return(new KeyValuePair <string, object>(currentProperty.PropertyName, value));
            }

            object keyValue = TraverseSelectorNodes(value, selectorNode.Children, currentPathSelector);

            return(new KeyValuePair <string, object>(currentProperty.PropertyName, keyValue));
        }
 public DefaultPropertyValueAccessor(T instance, IPropertyValueGetter getter, IPropertyValueSetter setter)
 {
     _getter   = getter is not null ? getter.Invoke : DefaultPropertyValueGetter.DefaultFunc;
     _setter   = setter is not null ? setter.Invoke : DefaultPropertyValueSetter.DefaultFunc;
     _type     = typeof(T);
     _instance = instance;
 }
 /// <summary>
 /// Initializes a new instance of <see cref="PropertyValueComparer"/>.
 /// </summary>
 /// <param name="dataDescriptions">The data descriptions containing sort information for all columns.</param>
 /// <param name="sortRecursively">Whether sorting should compare additional columns when equal values are found.</param>
 /// <param name="valueGetter">The <see cref="PropertyValueGetter"/> used to retrieve property values.</param>
 public PropertyValueComparer(List <UIPropertyGroupDescription> dataDescriptions, bool sortRecursively, IPropertyValueGetter valueGetter)
 {
     this.propertyValueGetter = valueGetter;
     this.dataDescriptions    = dataDescriptions;
     this.sortRecursively     = sortRecursively;
 }
示例#4
0
 public static IPropertyValueAccessor GetValueAccessor <T>(this T that, IPropertyValueGetter getter, IPropertyValueSetter setter)
 => A.GetValueAccessor(that, getter, setter);
示例#5
0
 public static IPropertyValueAccessor GetValueAccessor(this object that, Type type, IPropertyValueGetter getter, IPropertyValueSetter setter)
 => A.GetValueAccessor(that, type, getter, setter);
示例#6
0
 public static IPropertyValueAccessor GetValueAccessor <T>(T that, IPropertyValueGetter getter, IPropertyValueSetter setter)
 {
     return(new DefaultPropertyValueAccessor <T>(that, getter, setter));
 }
示例#7
0
 public static IPropertyValueAccessor GetValueAccessor(object that, Type type, IPropertyValueGetter getter, IPropertyValueSetter setter)
 {
     return(new DefaultPropertyValueAccessor(type, that, getter, setter));
 }
示例#8
0
 /// <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="propertyValueGetter"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public static bool TryGetPropertyValue <TVal>(object that, string propertyName, BindingFlags bindingAttr, IPropertyValueGetter propertyValueGetter, out TVal value)
 {
     return(Try.Create(() => propertyValueGetter
                       .SafeRefValue(DefaultPropertyValueGetter.Instance)
                       .Invoke(that.GetType(), that, propertyName, bindingAttr)
                       .As <TVal>())
            .GetSafeValueOut(out value, defaultVal: default)
            .IsSuccess);
 }
示例#9
0
 /// <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="value"></param>
 /// <param name="propertyValueGetter"></param>
 /// <returns>Value of the specific property in this that</returns>
 public static bool TryGetPropertyValue(object that, string propertyName, out object value, IPropertyValueGetter propertyValueGetter)
 {
     return(Try.Create(() => propertyValueGetter
                       .SafeRefValue(DefaultPropertyValueGetter.Instance)
                       .Invoke(that.GetType(), that, propertyName))
            .GetSafeValueOut(out value, defaultVal: null)
            .IsSuccess);
 }
示例#10
0
 /// <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>();
示例#11
0
 /// <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);
示例#12
0
 /// <summary>
 /// Initializes a new instance of <see cref="PropertyValueComparer"/>.
 /// </summary>
 /// <param name="dataDescriptions">The data descriptions containing sort information for all columns.</param>
 /// <param name="sortRecursively">Whether sorting should compare additional columns when equal values are found.</param>
 /// <param name="valueGetter">The <see cref="PropertyValueGetter"/> used to retrieve property values.</param>
 public PropertyValueComparer(List<UIPropertyGroupDescription> dataDescriptions, bool sortRecursively, IPropertyValueGetter valueGetter)
 {
     this.propertyValueGetter = valueGetter;
     this.dataDescriptions = dataDescriptions;
     this.sortRecursively = sortRecursively;
 }