/// <summary> /// Initializes a new instance of the <see cref="InstanceProxyingInstanciationContext"/> class. /// </summary> /// <param name="instanceDescriptor">The <see cref="InstanceDescriptor"/>.</param> /// <param name="collectionPropertyAssociation">The <see cref="CollectionPropertyAssociation"/>.</param> /// <param name="instanceRelationStore">The <see cref="IInstanceRelationStore"/>.</param> /// <param name="requestedType">The <see cref="Type"/> which is requested.</param> /// <exception cref="ArgumentNullException">The value of '<paramref name="requestedType"/>', '<paramref name="collectionPropertyAssociation"/>', '<paramref name="instanceDescriptor"/>' and '<paramref name="instanceRelationStore"/>' cannot be null.</exception> public CollectionProxyingInstanciationContext([NotNull] Type requestedType, [NotNull] IInstanceRelationStore instanceRelationStore, [NotNull] InstanceDescriptor instanceDescriptor, [NotNull] CollectionPropertyAssociation collectionPropertyAssociation) { if (instanceDescriptor == null) { throw new ArgumentNullException(nameof(instanceDescriptor)); } if (collectionPropertyAssociation == null) { throw new ArgumentNullException(nameof(collectionPropertyAssociation)); } if (requestedType == null) { throw new ArgumentNullException(nameof(requestedType)); } if (instanceRelationStore == null) { throw new ArgumentNullException(nameof(instanceRelationStore)); } this.InstanceDescriptor = instanceDescriptor; this.CollectionPropertyAssociation = collectionPropertyAssociation; this.RequestedType = requestedType; this.InstanceRelationStore = instanceRelationStore; }
private Object CreateDynamicListInstance([NotNull] CollectionPropertyAssociation collectionPropertyAssociation, [NotNull] InstanceResolutionContext InstanceResolutionContext, [NotNull] out MethodBase methodBase) { if (collectionPropertyAssociation == null) { throw new ArgumentNullException(nameof(collectionPropertyAssociation)); } if (InstanceResolutionContext == null) { throw new ArgumentNullException(nameof(InstanceResolutionContext)); } var newCollectionDefinition = typeof(ProxyableList <>); var collectionItemType = Type.GetType(collectionPropertyAssociation.AssemblyQualifiedItemTypeName, true, true); var realCollectionType = newCollectionDefinition.MakeGenericType(collectionItemType); methodBase = realCollectionType.GetMethod("AddNonProxied", BindingFlags.Instance | BindingFlags.NonPublic, null, new[] { collectionItemType }, new ParameterModifier[0]); var typeInstanciationContext = InstanceResolutionContext.NoChangeTracking && InstanceResolutionContext.NoLazyLoading ? new DefaultTypeInstanciationContext(realCollectionType, InstanceResolutionContext.InstanceRelationStore) : (ITypeInstanciationContext) new CollectionProxyingInstanciationContext(realCollectionType, InstanceResolutionContext.InstanceRelationStore, InstanceResolutionContext.InstanceDescriptor, collectionPropertyAssociation) { NoChangeTracking = InstanceResolutionContext.NoChangeTracking }; return(this.typeInstanciator.CreateInstance(typeInstanciationContext)); }
/// <summary> /// Initializes a new instance of the <see cref="CollectionAddMethodInterceptor"/> class. /// </summary> /// <param name="instanceDescriptor">The <see cref="Model.InstanceDescriptor"/>.</param> /// <param name="collectionPropertyAssociation">The <see cref="Model.Values.CollectionPropertyAssociation"/>.</param> /// <param name="collectionItemFactoryProvider">The <see cref="ICollectionItemFactoryProvider"/>.</param> /// <param name="instanceRelationStore">The <see cref="IInstanceRelationStore"/>.</param> /// <exception cref="ArgumentNullException">The value of '<paramref name="collectionPropertyAssociation"/>', '<paramref name="collectionItemFactoryProvider"/>', '<paramref name="instanceDescriptor"/>' and '<paramref name="instanceRelationStore"/>' cannot be null.</exception> public CollectionAddMethodInterceptor([NotNull] InstanceDescriptor instanceDescriptor, [NotNull] CollectionPropertyAssociation collectionPropertyAssociation, [NotNull] ICollectionItemFactoryProvider collectionItemFactoryProvider, [NotNull] IInstanceRelationStore instanceRelationStore) { if (instanceDescriptor == null) { throw new ArgumentNullException(nameof(instanceDescriptor)); } if (collectionPropertyAssociation == null) { throw new ArgumentNullException(nameof(collectionPropertyAssociation)); } if (collectionItemFactoryProvider == null) { throw new ArgumentNullException(nameof(collectionItemFactoryProvider)); } if (instanceRelationStore == null) { throw new ArgumentNullException(nameof(instanceRelationStore)); } this.instanceDescriptor = instanceDescriptor; this.collectionPropertyAssociation = collectionPropertyAssociation; this.collectionItemFactoryProvider = collectionItemFactoryProvider; this.instanceRelationStore = instanceRelationStore; }
/// <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); }
/// <summary> /// Initializes a new instance of the <see cref="CollectionRemoveMethodInterceptor"/> class. /// </summary> /// <param name="collectionPropertyAssociation">The <see cref="Model.Values.CollectionPropertyAssociation"/>.</param> /// <exception cref="ArgumentNullException">The value of '<paramref name="collectionPropertyAssociation"/>' cannot be null.</exception> public CollectionRemoveMethodInterceptor([NotNull] CollectionPropertyAssociation collectionPropertyAssociation) { if (collectionPropertyAssociation == null) { throw new ArgumentNullException(nameof(collectionPropertyAssociation)); } this.collectionPropertyAssociation = collectionPropertyAssociation; }
/// <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); }
/// <summary> /// Initializes a new instance of the <see cref="CollectionClearMethodInterceptor"/> class. /// </summary> /// <param name="collectionPropertyAssociation">The <see cref="Model.Values.CollectionPropertyAssociation"/>.</param> /// <exception cref="ArgumentNullException">The value of '<paramref name="collectionPropertyAssociation"/>' cannot be null.</exception> public CollectionClearMethodInterceptor([NotNull] CollectionPropertyAssociation collectionPropertyAssociation) { this.collectionPropertyAssociation = collectionPropertyAssociation; }