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)); }
public Object ResolveInstance(InstanceResolutionContext instanceResolutionContext) { if (instanceResolutionContext == null) { throw new ArgumentNullException(nameof(instanceResolutionContext)); } this.InitializedWithType = null; this.instanciatedType = null; this.instanceResolutionContext = null; this.instanceResolutionContext = instanceResolutionContext; Type type; try { type = Type.GetType(instanceResolutionContext.InstanceDescriptor.AssemblyQualifiedTypeName, true, true); } catch (TypeLoadException typeLoadException) { throw; } this.InitializedWithType = type; Object result; if (!instanceResolutionContext.InstanceRelationStore.TryGetRelated(instanceResolutionContext.InstanceDescriptor, out result)) { var typeInstanciationContext = instanceResolutionContext.NoChangeTracking && instanceResolutionContext.NoLazyLoading ? new DefaultTypeInstanciationContext(type, instanceResolutionContext.InstanceRelationStore) : (ITypeInstanciationContext) new InstanceProxyingInstanciationContext(instanceResolutionContext.InstanceDescriptor, type, instanceResolutionContext.InstanceRelationStore) { NoChangeTracking = instanceResolutionContext.NoChangeTracking, NoLazyLoading = instanceResolutionContext.NoLazyLoading }; this.instanciatedType = this.typeInstanciator.CreateInstance(typeInstanciationContext); result = this.instanciatedType; this.Walk(); instanceResolutionContext.InstanceRelationStore.CreateRelation(instanceResolutionContext.InstanceDescriptor, this.instanciatedType); } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="PropertyValueResolutionContext"/> class. /// </summary> /// <param name="propertyValue">The <see cref="IValueAssociation"/>.</param> /// <param name="InstanceResolutionContext">The parent <see cref="InstanceResolutionContext"/>.</param> /// <exception cref="ArgumentNullException">The value of '<paramref name="propertyValue"/>' and '<paramref name="InstanceResolutionContext"/>' cannot be null.</exception> public PropertyValueResolutionContext([NotNull] IValueAssociation propertyValue, [NotNull] InstanceResolutionContext InstanceResolutionContext) { if (propertyValue == null) { throw new ArgumentNullException(nameof(propertyValue)); } if (InstanceResolutionContext == null) { throw new ArgumentNullException(nameof(InstanceResolutionContext)); } this.PropertyValue = propertyValue; this.InstanceResolutionContext = InstanceResolutionContext; }