/// <summary> /// Creates a new instance of the class. Using this /// constructor allows to lazily create the /// <see cref="object"/>. /// The creation of the object happens when /// the properties of the object are reflected /// during the mapping /// </summary> /// <param name="objectFactory"> /// A factory that creates a new instance of the /// <see cref="object"/>. /// /// The factory must not return 'null' /// </param> /// <param name="assignablePropertyFactory"> /// A factory that creates instances of <see cref="IAssignableProperty{TAttribute}"/> /// </param> public AttributedObjectReflector(Func <object> objectFactory, IAssignablePropertyFactory <TAttribute> assignablePropertyFactory) { Guard.AgainstNullArgument(nameof(objectFactory), objectFactory); Guard.AgainstNullArgument(nameof(assignablePropertyFactory), assignablePropertyFactory); this.source = new Lazy <object>(objectFactory); this.propertyContainer = new Lazy <IPropertyContainer <TAttribute> >(this.CreateContainerForAttribute); this.assignablePropertyFactory = assignablePropertyFactory; }
/// <summary> /// Creates a new instance of the class. This constructor allows to /// specify a custom <see cref="IRegistrationService"/> and /// <see cref="IAssignablePropertyFactory{TAttribute}"/> /// </summary> /// <param name="registrationService"> /// An instance of <see cref="IRegistrationService"/> /// </param> /// <param name="assignablePropertyFactory"> /// An instance of <see cref="IAssignablePropertyFactory{TAttribute}"/> /// </param> /// <exception cref="ArgumentNullException"> /// Thrown if either of the arguments is null /// </exception> public DefaultMapper(IRegistrationService registrationService, IAssignablePropertyFactory <OptionAttribute> assignablePropertyFactory) { Guard.AgainstNullArgument(nameof(registrationService), registrationService); Guard.AgainstNullArgument(nameof(assignablePropertyFactory), assignablePropertyFactory); this.mapperDatas = new List <MapperData>(); this.UnmappedArguments = Enumerable.Empty <Argument>(); this.RegistrationService = registrationService; this.assignablePropertyFactory = assignablePropertyFactory; }
/// <summary> /// Creates a new instance of the class /// </summary> /// <param name="source"> /// The object that has properties with an applied /// attribute /// </param> /// <param name="assignablePropertyFactory"> /// A factory that creates instances of <see cref="IAssignableProperty{TAttribute}"/> /// </param> public AttributedObjectReflector(object source, IAssignablePropertyFactory <TAttribute> assignablePropertyFactory) : this(() => source, assignablePropertyFactory) { }
/// <summary> /// Creates a new instance of the class. This constructor allows /// to provide a custom <see cref="IAssignablePropertyFactory{TAttribute}"/> /// </summary> /// <param name="assignablePropertyFactory"> /// The factory that provides instances of <see cref="IAssignableProperty{TAttribute}"/> /// </param> /// <exception cref="ArgumentNullException"> /// Thrown if the passed argument is null /// </exception> public DefaultMapper(IAssignablePropertyFactory <OptionAttribute> assignablePropertyFactory) : this(new DefaultRegistrationService(), assignablePropertyFactory) { }