Exemplo n.º 1
0
        public DefaultMappingConfiguration()
        {
            ObjectFactory = new ActivatorObjectFactory();

            MappingObjects = new FuncToTypeList <object>
            {
                new FuncToTypeListItem <object>(MappingObjectsList.IsValid, typeof(MappingObjectsList)),
                new FuncToTypeListItem <object>(DataRowMappingObject.IsValid, typeof(DataRowMappingObject)),
                new FuncToTypeListItem <object>(DictionaryMappingObject.IsValid, typeof(DictionaryMappingObject)),
                new FuncToTypeListItem <object>(DataTableReaderMappingObject.IsValid, typeof(DataTableReaderMappingObject)),
                new FuncToTypeListItem <object>(PocoMappingObject.IsValid, typeof(PocoMappingObject))
            };

            MappingStrategies = new FuncToTypeList <MappingPair>
            {
                new FuncToTypeListItem <MappingPair>(ForEachSrcPropSetPropInDestEnumerablesMappingStrategy.CanMap, typeof(ForEachSrcPropSetPropInDestEnumerablesMappingStrategy)),
                new FuncToTypeListItem <MappingPair>(ForEachSrcPropSetPropInDestMappingStrategy.CanMap, typeof(ForEachSrcPropSetPropInDestMappingStrategy))
            };

            PropertyNameConverters = new FuncToTypeList <MappingPair>
            {
                new FuncToTypeListItem <MappingPair>(NopPropsMatcher.CanMap, typeof(NopPropsMatcher)),
                new FuncToTypeListItem <MappingPair>(RemoveWhiteSpacesPropsMatcher.CanMap, typeof(RemoveWhiteSpacesPropsMatcher))
            };
        }
Exemplo n.º 2
0
        public void CreateInstanceWithDifferentFactories()
        {
            const int TEST_ITERATIONS = 1000000;
            IFactory  factory         = null;

            #region new
            factory = new NewAccountFactory();

            // create an instance so that Activators can
            // cache the type/constructor/whatever
            factory.CreateInstance(Type.EmptyTypes);

            GC.Collect();
            GC.WaitForPendingFinalizers();

            Timer timer = new Timer();
            timer.Start();
            for (int i = 0; i < TEST_ITERATIONS; i++)
            {
                factory.CreateInstance(Type.EmptyTypes);
            }
            timer.Stop();
            double newFactoryResult = 1000000 * (timer.Duration / (double)TEST_ITERATIONS);
            #endregion

            #region activator
            factory = new ActivatorObjectFactory().CreateFactory(typeof(Account), Type.EmptyTypes);

            // create an instance so that Activators can
            // cache the type/constructor/whatever
            factory.CreateInstance(Type.EmptyTypes);

            GC.Collect();
            GC.WaitForPendingFinalizers();

            timer.Start();
            for (int i = 0; i < TEST_ITERATIONS; i++)
            {
                factory.CreateInstance(Type.EmptyTypes);
            }
            timer.Stop();
            double activatorFactoryResult = 1000000 * (timer.Duration / (double)TEST_ITERATIONS);
            #endregion

            #region Emit
            factory = new EmitObjectFactory().CreateFactory(typeof(Account), Type.EmptyTypes);

            // create an instance so that Activators can
            // cache the type/constructor/whatever
            factory.CreateInstance(Type.EmptyTypes);

            GC.Collect();
            GC.WaitForPendingFinalizers();

            timer.Start();
            for (int i = 0; i < TEST_ITERATIONS; i++)
            {
                factory.CreateInstance(Type.EmptyTypes);
            }
            timer.Stop();
            double emitFactoryResult = 1000000 * (timer.Duration / (double)TEST_ITERATIONS);
            #endregion

            // Print results
            Console.WriteLine(
                "Create " + TEST_ITERATIONS.ToString() + " objects via factory :"
                + "\nNew : \t\t\t" + newFactoryResult.ToString("F3")
                + "\nActivator : \t\t" + activatorFactoryResult.ToString("F3") + " Ratio : " + ((activatorFactoryResult / newFactoryResult)).ToString("F3")
                + "\nEmit IL : \t\t\t" + emitFactoryResult.ToString("F3") + " Ratio : " + ((emitFactoryResult / newFactoryResult)).ToString("F3"));
        }