/// <summary> /// Creates new instances of <see cref="InstanceDescriptor"/> instances based on the information contained by the supplied <see cref="InstanceDescriptorCreationContext"/>. /// </summary> /// <param name="instanceDescriptorCreationContext">The <see cref="InstanceDescriptorCreationContext"/>.</param> /// <exception cref="ArgumentNullException">The value of '<paramref name="instanceDescriptorCreationContext"/>' cannot be null.</exception> /// <returns>The newly created <see cref="InstanceDescriptor"/>.</returns> public InstanceDescriptor CreateInstanceDescriptor(InstanceDescriptorCreationContext instanceDescriptorCreationContext) { if (instanceDescriptorCreationContext == null) { throw new ArgumentNullException(nameof(instanceDescriptorCreationContext)); } InstanceDescriptor resultInstanceDescriptor; if (!instanceDescriptorCreationContext.InstanceRelationStore.TryGetRelated(instanceDescriptorCreationContext.CurrentInstance, out resultInstanceDescriptor)) { var instanceType = instanceDescriptorCreationContext.CurrentInstance.GetType().TryUnwrapProxiedType(); resultInstanceDescriptor = new InstanceDescriptor(instanceType); foreach (var propertyInfo in this.propertyReflector.ReflectProperties(instanceDescriptorCreationContext.CurrentInstance)) { var propertyValueFactory = this.propertyValueFactoryProvider.GetPropertyValueFactory(propertyInfo.PropertyType); var propertyValue = propertyValueFactory.CreatePropertyValue(instanceDescriptorCreationContext.CreatePropertyValueCreationContext(propertyInfo)); var propertyValueHandler = this.propertyValueHandlerFactory.GetPropertyValueHandler(propertyValue, propertyInfo); propertyValueHandler.HandlePropertyValue(resultInstanceDescriptor, propertyValue, propertyInfo); } this.typeAliasWalker.CreateAliases(resultInstanceDescriptor, instanceDescriptorCreationContext.CurrentInstance.GetType()); instanceDescriptorCreationContext.InstanceRelationStore.CreateRelation(resultInstanceDescriptor, instanceDescriptorCreationContext.CurrentInstance); } return(resultInstanceDescriptor); }
/// <summary> /// Initializes a new instance of the <see cref="CollectionItemCreationContext"/> class. /// </summary> /// <param name="itemInstance">The instance of the collection item.</param> /// <param name="instanceDescriptorCreationContext">The parent <see cref="InstanceDescriptorCreationContext"/>.</param> /// <exception cref="ArgumentNullException">The value of '<paramref name="instanceDescriptorCreationContext"/>' cannot be null.</exception> public CollectionItemCreationContext([CanBeNull] Object itemInstance, [NotNull] InstanceDescriptorCreationContext instanceDescriptorCreationContext) { if (instanceDescriptorCreationContext == null) { throw new ArgumentNullException(nameof(instanceDescriptorCreationContext)); } this.ItemInstance = itemInstance; this.InstanceDescriptorCreationContext = instanceDescriptorCreationContext; }
/// <summary> /// Initializes a new instance of the <see cref="PropertyValueCreationContext"/> class. /// </summary> /// <param name="propertyInfo">The <see cref="PropertyInfo"/>.</param> /// <param name="instanceDescriptorCreationContext">The parent <see cref="InstanceDescriptorCreationContext"/>.</param> /// <exception cref="ArgumentNullException">The value of '<paramref name="propertyInfo"/>' and '<paramref name="instanceDescriptorCreationContext"/>' cannot be null.</exception> public PropertyValueCreationContext([NotNull] PropertyInfo propertyInfo, [NotNull] InstanceDescriptorCreationContext instanceDescriptorCreationContext) { if (propertyInfo == null) { throw new ArgumentNullException(nameof(propertyInfo)); } if (instanceDescriptorCreationContext == null) { throw new ArgumentNullException(nameof(instanceDescriptorCreationContext)); } this.PropertyInfo = propertyInfo; this.InstanceDescriptorCreationContext = instanceDescriptorCreationContext; }
internal static PropertyValueCreationContext ForExistingPropertyValue([NotNull] PropertyInfo propertyInfo, [NotNull] InstanceDescriptorCreationContext instanceDescriptorCreationContext, [NotNull] Object value) { if (propertyInfo == null) { throw new ArgumentNullException(nameof(propertyInfo)); } if (instanceDescriptorCreationContext == null) { throw new ArgumentNullException(nameof(instanceDescriptorCreationContext)); } if (value == null) { throw new ArgumentNullException(nameof(value)); } return(new PropertyValueCreationContext(propertyInfo, instanceDescriptorCreationContext) { contextValue = value }); }