public TValue ResolveValue <TValue>(object data, IPropertyValueResolver propertyValueResolver) where TValue : IConvertible { var propertyValue = ResolveValue(data, propertyValueResolver); var type = typeof(TValue); return((TValue)Convert.ChangeType(propertyValue, type)); }
public object ResolveValue(object data, IPropertyValueResolver propertyValueResolver) { var propertyValue = _property.ResolveValue(data, propertyValueResolver); if (_subPath != null) { if (propertyValue == null) { throw new NullReferenceException($"Intermediate property ${_property} is null. Path: ${ToString()}"); } return(_subPath.ResolveValue(propertyValue, propertyValueResolver)); } return(propertyValue); }
/// <summary> /// Resolves the collection from the <see cref="CollectionPropertyAssociation"/>. /// </summary> /// <param name="propertyValueResolutionContext">The <see cref="PropertyValueResolutionContext"/>.</param> /// <exception cref="ArgumentNullException">The value of '<paramref name="propertyValueResolutionContext"/>' cannot be null.</exception> /// <returns>The resolved value.</returns> public Object ResolveValue(PropertyValueResolutionContext propertyValueResolutionContext) { if (propertyValueResolutionContext == null) { throw new ArgumentNullException(nameof(propertyValueResolutionContext)); } var collectionPropertyAssociation = (CollectionPropertyAssociation)propertyValueResolutionContext.PropertyValue; MethodBase addMethod; var newCollectionInstance = this.CreateDynamicListInstance(collectionPropertyAssociation, propertyValueResolutionContext.InstanceResolutionContext, out addMethod); IPropertyValueResolver propertyValueResolver = null; foreach (var item in collectionPropertyAssociation.CollectionItemDescriptors.Cast <IValueAssociation>().ToList()) { var itemPropertyResolutionContext = propertyValueResolutionContext.InstanceResolutionContext.CreatePropertyValueResolutionContext(item); this.ResolveCollectionItemAndAdd(newCollectionInstance, addMethod, itemPropertyResolutionContext, ref propertyValueResolver); } return(newCollectionInstance); }
public override object ResolveValue(object data, IPropertyValueResolver propertyValueResolver) { return(propertyValueResolver.ResolveArrayItemProperty(this, data)); }
public virtual object ResolveValue(object data, IPropertyValueResolver propertyValueResolver) { return(propertyValueResolver.ResolveProperty(this, data)); }
/// <summary> /// Resolves the collection item and adds it to the collection. /// If <paramref name="itemPropertyValueResolver"/> is null, it will be resolved for the <see cref="IValueAssociation"/>, otherweise the supplied instance will be used. /// </summary> /// <param name="collection">An instance of the created <see cref="List{T}"/>.</param> /// <param name="addMethod">The reference to the Add-method.</param> /// <param name="propertyValueResolutionContext">The <see cref="PropertyValueResolutionContext"/>.</param> /// <param name="itemPropertyValueResolver">The used or created resolved <see cref="IPropertyValueResolver"/> instance.</param> private void ResolveCollectionItemAndAdd([NotNull] Object collection, [NotNull] MethodBase addMethod, [NotNull] PropertyValueResolutionContext propertyValueResolutionContext, [CanBeNull] ref IPropertyValueResolver itemPropertyValueResolver) { if (collection == null) { throw new ArgumentNullException(nameof(collection)); } if (addMethod == null) { throw new ArgumentNullException(nameof(addMethod)); } if (propertyValueResolutionContext == null) { throw new ArgumentNullException(nameof(propertyValueResolutionContext)); } if (itemPropertyValueResolver == null) { var propertyValueResolver = this.propertyValueResolvers.First(pvr => pvr.Value.CanResolveValue(propertyValueResolutionContext.PropertyValue)); itemPropertyValueResolver = propertyValueResolver.Value; } var resolvedValue = itemPropertyValueResolver.ResolveValue(propertyValueResolutionContext); addMethod.Invoke(collection, new[] { resolvedValue }); }