示例#1
0
        private static void Case1()
        {
            IAutoMobileFactory factory    = BMWFactory.GetInstance();
            IAutoMobile        autoMobile = factory.Make();

            autoMobile.Start();
            autoMobile.Stop();

            IAutoMobileFactory factory1    = AudiFactory.GetInstance();
            IAutoMobile        autoMobile1 = factory1.Make();

            autoMobile1.Start();
            autoMobile1.Stop();

            IAutoMobileFactory factory2    = TeslaFactory.GetInstance();
            IAutoMobile        autoMobile2 = factory2.Make();

            autoMobile2.Start();
            autoMobile2.Stop();
        }
示例#2
0
        public static void LoadFromFile()
        {
            try
            {
                // Console.WriteLine(typeof(AudiFactory).AssemblyQualifiedName);
                string class1 = ConfigurationManager.AppSettings["load"];
                // Console.WriteLine(class1);
                //MethodBase type = Type.GetType(class1).GetMethod("GetInstance", null);
                MethodInfo type = Type.GetType(class1).GetMethod("GetInstance");
                //MethodInfo[] type = Type.GetType(class1).GetMethods();
                IAutoMobileFactory factory = null;
                //   var m = type.Invoke("GetInstance", new Type[0]);
                // Console.WriteLine(type);
                //  factory = (IAutoMobileFactory)type[0];
                factory = (IAutoMobileFactory)type.Invoke(null, null);
                IAutoMobile auto = factory.Make();
                auto.Start();
                auto.Stop();



                /*  if (appSettings.Count == 0)
                 * {
                 *    Console.WriteLine("AppSettings is empty.");
                 * }
                 * else
                 * {
                 *    foreach (var key in appSettings.AllKeys)
                 *    {
                 *        Console.WriteLine("Key: {0} Value: {1}", key, appSettings["Loadfactory"]);
                 *    }
                 * }*/
            }
            catch (ConfigurationErrorsException)
            {
                Console.WriteLine("Error reading app settings");
            }
        }