예제 #1
0
        /// <summary>
        /// Called cfg.For().Configure(...). Used to create a sub configuration
        /// with a property accessor for the specified type.
        /// </summary>
        /// <typeparam name="TSub">The new subt type to configure.</typeparam>
        /// <param name="accessor">Lambda accessor that takes the current type
        /// object and returns the sub object type.</param>
        /// <param name="configure">Lambda expression that builds the configuration
        /// for the new type.</param>
        public void Configure <TSub>(Func <T, TSub> accessor, Action <IConfigureChain <TSub> > configure)
        {
            // We are in the context of a For<type>(...).Configure<type2>() method and
            // therefore we have a ParentType, For Type, and now a new SubType. Basically
            // you have the following:
            //
            //   cfg.For<Type1>().Configure<Type2>(...)
            //
            // The cfg object carries the parent type (TParent),
            // the For carries the sub type (T),
            // and the Confgirure (this call), carries the third type (TSub).
            //
            // In this case, we create two mapper objects. The reason is because you
            // may have a TypeName specification which will go with the For<type> and
            // not the TSub type. Therefore we create a new SelectorMapper and
            // associate the TypeName accessors to that node and then create another
            // one for this configuration.

            SelectorMapper <T> mapper = null;

            Selector.Configure <T>(cfg => mapper = (SelectorMapper <T>)cfg, LookupStrategyEnum.InheritChain, TypeNameResourceKey, TypeNameAccessor);


            SelectorMapper <TSub> subMapper = new SelectorMapperSub <T, TSub>(accessor, LookupStrategyEnum.ConcreteOnly);

            mapper.Mapper.Add <T>(subMapper);
            configure(subMapper);
        }
        /// <summary>
        /// Configures a mapping that is based on property value of the object.
        /// </summary>
        /// <typeparam name="TSub">Sub type to configure</typeparam>
        /// <param name="accessor">Lambda expression used to access the sub property.</param>
        /// <param name="configure">Lambda expression used to configure the mapping.</param>
        public void Configure <TSub>(Func <T, TSub> accessor, Action <IConfigureChain <TSub> > configure)
        {
            SelectorMapper <TSub> mapper = new SelectorMapperSub <T, TSub>(accessor);

            Selector.AddConditionItem(Condition, mapper);
            configure(mapper);
        }
        /// <summary>
        /// Configures a mapping that is based on property value of the object.
        /// </summary>
        /// <typeparam name="TSub">Sub type to configure</typeparam>
        /// <param name="accessor">Lambda expression used to access the sub property.</param>
        /// <param name="configure">Lambda expression used to configure the mapping.</param>
        public void Configure <TSub>(Func <T, TSub> accessor, Action <IConfigureChain <TSub> > configure)
        {
            SelectorMapper <TSub> mapper = new SelectorMapperSub <T, TSub>(accessor);

            Selector.DefaultItem = mapper;
            configure(mapper);
        }