Пример #1
0
        public static ChinaCar CreateNewChinaCar(string name, int engineVol, int tankVol, string bodyType)
        //Action<IProductOptions> optionalParams)
        {
            var chinaCar = new ChinaCar(name, engineVol, tankVol, bodyType);

            return(chinaCar);
        }
Пример #2
0
        public static ChinaCar CreateNewChinaCar(string brand, string name, int engineVol, int tankVol, string bodyType,
                                                 string countryOfOrigin, int percentOfOriginalPieces)
        //Action<IProductOptions> optionalParams)
        {
            var chinaCar = new ChinaCar(brand, name, engineVol, tankVol, bodyType, countryOfOrigin, percentOfOriginalPieces);

            return(chinaCar);
        }
Пример #3
0
        //public bool cpModel(ChinaCar old, ChinaCar newObj)
        //{
        //    1.cpInt(2);
        //    "1".cpStringd("3");

        //    return old.Id == newObj.Id;
        //}



        static void Main(string[] args)
        {
            HashSet <char> hash = new HashSet <char>();
            string         str  = "abcdefgabhib";

            foreach (var item in str)
            {
                hash.Add(item);
            }

            //Console.Title = "C# 学习 Demo";//设置窗口标题

            var model = new ChinaCar()
            {
                Brand    = "大众",
                CarName  = "我的小车",
                Color    = "Red",
                Id       = 1,
                MadeTime = DateTime.Now,
                SeatNum  = 5
            };

            var model2 = new ChinaCar()
            {
                Brand    = "大众1",
                CarName  = "我的小车1",
                Color    = "Redsss",
                Id       = 5,
                MadeTime = DateTime.Now,
                SeatNum  = 5
            };


            var h = new HashSet <ChinaCar>(new cp <ChinaCar>());

            h.Add(model2);
            h.Add(model);

            var tClass   = new TClass();
            var carClass = new CarClass();

            //carClass.MadeChinaCar(model);


            //Console.WriteLine(tClass.GetGeneric(model).ToString());
            ////强制泛型类型  tClass.getTToString<int>(1)
            //Console.WriteLine(tClass.GetGeneric<int>(1));
            //Console.WriteLine(tClass.GetGenericByModel(model));

            //ParallelClass.ParallelInvokeMethod();

            //TaskClass.TaskRun();

            //ParallelClass.ParallelTask();


            //var delegateClass = new DelegateClass();
            //var delega = new DelegateClass();
            //var method = new DelegateClass.modelDelegate(delega.modelDeleegateFun);
            //method.Invoke(model);

            //delega.GenericFun(() => tClass.GetByModel(model), model);

            for (int i = 0; i < 5; i++)
            {
                Task.Run(() =>
                {
                    DemoClass.Show();
                });
            }

            var listTask = new List <Task>();

            for (int i = 0; i < 5; i++)
            {
                listTask.Add(Task.Run(() =>
                {
                    DemoClass.Show();
                }));
            }
            Task.WaitAll(listTask.ToArray(), 1000);

            Console.Read();
        }
Пример #4
0
        private static void Main(string[] args)
        {
            ServiceLocator.RegisterAll();
            GermanyCarFactory = ServiceLocator.Get <GermanyCarFactory>();
            JapanCarFactory   = ServiceLocator.Get <JapanCarFactory>();

            GermanyCar bmw = GermanyCarFactory.CreateNewGermanyCar("BMW", 3500, 100, "Sedan");

            GermanyCar audi = GermanyCarFactory.CreateNewGermanyCar("Audi", 2500, 80, "Universal");

            JapanCar honda = JapanCarFactory.CreateNewJapanCar("Honda", 2000, 70, "Hatchbag");

            var      ChinaCarFactory = new ChinaCarFactory();
            ChinaCar byd             = ChinaCarFactory.CreateNewChinaCar("BYD", 1300, 50, "ChinaStyle");

            TuneCar(audi);
            Console.WriteLine(new string('=', 30));
            //TuneCar(bmw);
            //Console.WriteLine(new string('=', 30));
            //TuneCar(honda);
            //Console.WriteLine(new string('=', 30));

            // Germany car info

            #region

            Console.WriteLine(new string('-', 30));
            Console.WriteLine("GermanyCar : " + bmw.Name);
            Console.WriteLine(bmw.Name + " engine: " + bmw.EngineIsStarted);
            Console.WriteLine(bmw.Name + " lights: " + bmw.lights);
            Console.WriteLine(new string('-', 30));
            bmw.CheckAllSystem();
            bmw.StartEngine();

            #endregion

            // Japan car info

            #region

            Console.WriteLine("JapanCar : " + honda.Name);
            Console.WriteLine(honda.Name + " engine: " + honda.EngineIsStarted);
            Console.WriteLine(honda.Name + " lights: " + honda.lights);
            Console.WriteLine(new string('-', 30));
            honda.CheckAllSystem();
            honda.StartEngine();
            honda.lights = false;

            #endregion

            // China car info

            #region

            Console.WriteLine("ChinaCar : " + byd.Name);
            Console.WriteLine(byd.Name + " engine: " + byd.EngineIsStarted);
            Console.WriteLine(byd.Name + " lights: " + byd.lights);
            Console.WriteLine(new string('-', 30));
            byd.CheckAllSystem();
            byd.StartEngine();

            #endregion

            Console.WriteLine(new string('-', 30));

            audi.BattOk = false;
            byd.BattOk  = false;
            Service srv = new Service();

            // Service check

            #region

            srv.Check(bmw);
            srv.Check(honda);
            srv.Check(byd);
            Console.WriteLine();
            srv.Check(audi);
            srv.Repair(audi);
            srv.Check(audi);
            Console.WriteLine();

            #endregion

            Console.WriteLine("!!! Start Engine !!!");
            Console.WriteLine(new string('-', 30));

            Console.WriteLine("     " + bmw);
            Console.WriteLine(honda.ToString());
            Console.WriteLine(byd.ToString());
            Console.WriteLine(audi.ToString());

            Console.WriteLine(new string('-', 30));
            UseProxy(bmw, audi, honda);

            // Observer RDS

            #region

            Console.WriteLine(new string('=', 30));
            RdsTrans = new RDSTransmitter();
            RdsTrans.Subscribe(audi.Receiver);
            RdsTrans.Subscribe(byd.Receiver);
            RdsTrans.LastNews = DateTime.Now + " Have an ice day ";
            RdsTrans.UnSubscribe(byd.Receiver);
            RdsTrans.LastNews = "Weather for this evening";
            Console.WriteLine(new string('=', 30));

            #endregion

            // Template method

            #region

            bmw.StartAirConditioner();
            audi.StartAirConditioner();
            honda.StartAirConditioner();
            Console.WriteLine(audi.ToString());

            #endregion

            Console.ReadLine();
        }
Пример #5
0
 public void modelDeleegateFun(ChinaCar model)
 {
     Console.WriteLine("通过委托返回对象的名称:{0}", model.CarName);
 }