/// <summary>
        /// Creates a new <see cref="CollectionItem"/> and outputs the used <see cref="ICollectionItemFactory"/> for caching purpose.
        /// If <paramref name="collectionItemFactory"/> is null, the instance will be determined and set via <c>ref</c>, so it is possible that the next call can supply this instance for faster processing.
        /// </summary>
        /// <param name="collectionPropertyAssociation">The <see cref="CollectionPropertyAssociation"/>.</param>
        /// <param name="item">The instance of the collection item.</param>
        /// <param name="propertyValueCreationContext">The <see cref="PropertyValueCreationContext"/>.</param>
        /// <param name="collectionItemFactory"></param>
        private void CreateAndAddCollectionItem([NotNull] CollectionPropertyAssociation collectionPropertyAssociation,
                                                [CanBeNull] Object item,
                                                [NotNull] PropertyValueCreationContext propertyValueCreationContext,
                                                [NotNull] ICollectionItemFactory collectionItemFactory)
        {
            if (collectionPropertyAssociation == null)
            {
                throw new ArgumentNullException(nameof(collectionPropertyAssociation));
            }

            if (propertyValueCreationContext == null)
            {
                throw new ArgumentNullException(nameof(propertyValueCreationContext));
            }

            if (collectionItemFactory == null)
            {
                throw new ArgumentNullException(nameof(collectionItemFactory));
            }

            var collectionItem = collectionItemFactory.CreateCollectionItem(propertyValueCreationContext.InstanceDescriptorCreationContext.CreateCollectionItemCreationContext(item));

            if (collectionItem is IgnorableCollectionItem)
            {
                return;
            }

            collectionPropertyAssociation.CollectionItemDescriptors.Add(collectionItem);
        }
示例#2
0
        /// <summary>
        /// Additionally supplies the value of the <see cref="PropertyInfo"/> to the implementor.
        /// </summary>
        /// <param name="propertyValueCreationContext">The <see cref="PropertyValueCreationContext"/>.</param>
        /// <param name="propertyValue">The property value.</param>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="propertyValueCreationContext"/>' cannot be null.</exception>
        /// <returns>A derivation of the <see cref="PropertyValue"/>.</returns>
        protected override PropertyValue CreatePropertyValueCore(PropertyValueCreationContext propertyValueCreationContext, Object propertyValue)
        {
            if (propertyValue == null)
            {
                return(new IgnorablePropertyValue());
            }

            if (propertyValueCreationContext == null)
            {
                throw new ArgumentNullException(nameof(propertyValueCreationContext));
            }

            InstanceDescriptor instanceDescriptor;

            if (propertyValueCreationContext.InstanceDescriptorCreationContext.InstanceRelationStore.TryGetRelated(propertyValue, out instanceDescriptor))
            {
                if (instanceDescriptor == null)
                {
                    throw new InvalidOperationException();
                }
            }

            if (instanceDescriptor == null)
            {
                instanceDescriptor = this.instanceDescriptorFactory.Value.CreateInstanceDescriptor(propertyValueCreationContext.InstanceDescriptorCreationContext.CreateChildContext(propertyValue));
            }

            return(new InstancePropertyAssociation(instanceDescriptor, propertyValueCreationContext.PropertyInfo));
        }
示例#3
0
        protected override PropertyValue CreateNewPropertyValue(IPropertyValueFactory propertyValueFactory, Object instance,
                                                                PropertyInfo propertyInfo, Object value)
        {
            if (propertyValueFactory == null)
            {
                throw new ArgumentNullException(nameof(propertyValueFactory));
            }

            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            if (propertyInfo == null)
            {
                throw new ArgumentNullException(nameof(propertyInfo));
            }

            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            return(propertyValueFactory.CreatePropertyValue(
                       PropertyValueCreationContext.ForExistingPropertyValue(propertyInfo,
                                                                             new InstanceDescriptorCreationContext(instance, this.instanceRelationStore), value)));
        }
示例#4
0
        /// <summary>
        /// Additionally supplies the value of the <see cref="PropertyInfo"/> to the implementor.
        /// </summary>
        /// <param name="propertyValueCreationContext">The <see cref="PropertyValueCreationContext"/>.</param>
        /// <param name="propertyValue">The property value.</param>
        /// <returns>A derivation of the <see cref="PropertyValue"/>.</returns>
        protected override PropertyValue CreatePropertyValueCore(PropertyValueCreationContext propertyValueCreationContext, Object propertyValue)
        {
            if (propertyValue == null)
            {
                return(new IgnorablePropertyValue());
            }

            var value = Guid.Parse(propertyValue.ToString());

            return(new GuidPropertyValue(value, propertyValueCreationContext.PropertyInfo));
        }
示例#5
0
        /// <summary>
        /// Finally creates the <see cref="PropertyValue"/> derivation using the information contained in the supplied <see cref="PropertyValueCreationContext"/>.
        /// </summary>
        /// <param name="propertyValueCreationContext">The <see cref="PropertyValueCreationContext"/>.</param>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="propertyValueCreationContext"/>' cannot be null.</exception>
        /// <returns>A derivation of the <see cref="PropertyValue"/>.</returns>
        public PropertyValue CreatePropertyValue(PropertyValueCreationContext propertyValueCreationContext)
        {
            if (propertyValueCreationContext == null)
            {
                throw new ArgumentNullException(nameof(propertyValueCreationContext));
            }

            var propertyValue = propertyValueCreationContext.GetValue(propertyValueCreationContext.InstanceDescriptorCreationContext.CurrentInstance);

            return(this.CreatePropertyValueCore(propertyValueCreationContext, propertyValue));
        }
        /// <summary>
        /// Additionally supplies the value of the <see cref="PropertyInfo"/> to the implementor.
        /// </summary>
        /// <param name="propertyValueCreationContext">The <see cref="PropertyValueCreationContext"/>.</param>
        /// <param name="propertyValue">The property value.</param>
        /// <returns>A derivation of the <see cref="PropertyValue"/>.</returns>
        protected override PropertyValue CreatePropertyValueCore(PropertyValueCreationContext propertyValueCreationContext, Object propertyValue)
        {
            if (propertyValue == null)
            {
                return(new IgnorablePropertyValue());
            }

            var value = (Byte[])propertyValue;

            return(new ByteArrayPropertyValue(value, propertyValueCreationContext.PropertyInfo));
        }
        /// <summary>
        /// Additionally supplies the value of the <see cref="PropertyInfo"/> to the implementor.
        /// </summary>
        /// <param name="propertyValueCreationContext">The <see cref="PropertyValueCreationContext"/>.</param>
        /// <param name="propertyValue">The property value.</param>
        /// <returns>A derivation of the <see cref="PropertyValue"/>.</returns>
        protected override PropertyValue CreatePropertyValueCore(PropertyValueCreationContext propertyValueCreationContext, Object propertyValue)
        {
            if (propertyValue == null)
            {
                return(new IgnorablePropertyValue());
            }

            var underlyingEnumType = propertyValueCreationContext.PropertyInfo.PropertyType.GetEnumUnderlyingType();

            var propertyValueFactory = this.propertyValueFactoryProvider.Value.GetPropertyValueFactory(underlyingEnumType);

            return(propertyValueFactory.CreatePropertyValue(PropertyValueCreationContext.ForExistingPropertyValue(propertyValueCreationContext.PropertyInfo, propertyValueCreationContext.InstanceDescriptorCreationContext, Convert.ChangeType(propertyValue, underlyingEnumType))));
        }
        /// <summary>
        /// Additionally supplies the value of the <see cref="PropertyInfo"/> to the implementor.
        /// </summary>
        /// <param name="propertyValueCreationContext">The <see cref="PropertyValueCreationContext"/>.</param>
        /// <param name="propertyValue">The property value.</param>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="propertyValueCreationContext"/>' cannot be null.</exception>
        /// <returns>A derivation of the <see cref="PropertyValue"/>.</returns>
        protected override PropertyValue CreatePropertyValueCore(PropertyValueCreationContext propertyValueCreationContext, Object propertyValue)
        {
            if (propertyValue == null)
            {
                return(new IgnorablePropertyValue());
            }

            if (propertyValueCreationContext == null)
            {
                throw new ArgumentNullException(nameof(propertyValueCreationContext));
            }

            var itemType = this.GetICollectionType(propertyValueCreationContext.PropertyInfo.PropertyType);
            var result   = new CollectionPropertyAssociation(itemType, propertyValueCreationContext.PropertyInfo);

            var collectionItemFactory = this.collectionItemFactoryProvider.GetCollectionItemFactory(itemType);

            foreach (var item in (IEnumerable)propertyValue)
            {
                this.CreateAndAddCollectionItem(result, item, propertyValueCreationContext, collectionItemFactory);
            }

            return(result);
        }
示例#9
0
 protected abstract PropertyValue CreatePropertyValueCore([NotNull] PropertyValueCreationContext propertyValueCreationContext, [CanBeNull] Object propertyValue);