Exemple #1
0
        public void TestFactorySpeed()
        {
            KeyedFactory <int, Product> factory = new KeyedFactory <int, Product>();
            int key = 0;

            factory.RegisterType <Product>(key++);
            factory.RegisterMethod(key++, delegate { return(Activator.CreateInstance <Product>()); });
            factory.RegisterMethod(key++, delegate { return((Product)Activator.CreateInstance(typeof(Product))); });
            factory.RegisterMethod(key++, delegate { return(new Product()); });
            factory.RegisterImmutable(key++, new Product());
            factory.RegisterPrototype(key++, new Product());

            ConstructorInfo ci = typeof(Product).GetConstructor(Type.EmptyTypes);

            factory.RegisterMethod(key++, delegate { return((Product)ci.Invoke(null)); });

            foreach (int k in factory.Keys)
            {
                factory.Create(k);
            }

            int iterationCount = 1000000;

            foreach (int k in factory.Keys)
            {
                Stopwatch watch = Stopwatch.StartNew();
                for (int i = 0; i < iterationCount; i++)
                {
                    factory.Create(k);
                }
                Console.WriteLine("{0} {1}", k, watch.ElapsedMilliseconds);
            }
        }
        public void TestFactorySpeed()
        {
            KeyedFactory<int, Product> factory = new KeyedFactory<int, Product>();
            int key = 0;
            factory.RegisterType<Product>(key++);
            factory.RegisterMethod(key++, delegate { return Activator.CreateInstance<Product>(); });
            factory.RegisterMethod(key++, delegate { return (Product) Activator.CreateInstance(typeof (Product));}) ;
            factory.RegisterMethod(key++, delegate { return new Product(); });
            factory.RegisterImmutable(key++, new Product());
            factory.RegisterPrototype(key++, new Product());

            ConstructorInfo ci = typeof (Product).GetConstructor(Type.EmptyTypes);
            factory.RegisterMethod(key++, delegate { return (Product) ci.Invoke(null); });

            foreach (int k in factory.Keys)
                factory.Create(k);

            int iterationCount = 1000000;

            foreach (int k in factory.Keys)
            {
                Stopwatch watch = Stopwatch.StartNew();
                for (int i = 0; i < iterationCount; i++)
                    factory.Create(k);
                Console.WriteLine("{0} {1}", k, watch.ElapsedMilliseconds);
            }
        }
        public void TestFactory()
        {
            KeyedFactory<string, string> f = new KeyedFactory<string, string>();
            f.RegisterImmutable("bla", "bla");
            f.RegisterMethod("bla1", delegate { return "bla1"; });

            Assert.AreEqual("bla", f.Create("bla"));
            Assert.AreEqual("bla1", f.Create("bla1"));
        }
Exemple #4
0
        public void TestFactory()
        {
            KeyedFactory <string, string> f = new KeyedFactory <string, string>();

            f.RegisterImmutable("bla", "bla");
            f.RegisterMethod("bla1", delegate { return("bla1"); });

            Assert.AreEqual("bla", f.Create("bla"));
            Assert.AreEqual("bla1", f.Create("bla1"));
        }
Exemple #5
0
 public void Run()
 {
     foreach (string key in _commands.Keys)
     {
         if (!string.Equals(key, NoKey, StringComparison.InvariantCultureIgnoreCase) && HasKey(key))
         {
             _commands.Create(key).Execute();
             return;
         }
     }
     if (_commands.IsRegistered(NoKey))
     {
         _commands.Create(NoKey).Execute();
     }
 }
Exemple #6
0
        void eventQueue_EventOccurs(object sender, EventArgs <string> e)
        {
            TTask task = _taskFactory.Create(e.Item);

            StartTask(task);
        }
Exemple #7
0
        /// <summary>
        /// Resolves <paramref name="converterType"/> and returns new instance of the associated <see cref="IFieldConverter"/>.
        /// </summary>
        /// <param name="converterType">type of the field converter to instantiate.</param>
        /// <returns>New instance of the <see cref="IFieldConverter"/>.</returns>
        public IFieldConverter Resolve(Type converterType)
        {
            Guard.CheckNotNull(nameof(converterType), converterType);

            return(new FieldConverterWrapper(converterType, _fieldConvertersBuilders.Create(converterType)));
        }