Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Inventory inventory = new Inventory();

            initializeInventory(inventory);

            Guitar whatErinLikes = new Guitar("", 0, Builder_Enum.FENDER, "Stratocastor",
                                              Type_Enum.ACOUSTIC, Wood_Enum.ALDER, Wood_Enum.ALDER);

            List <Guitar> matchingGuitar = inventory.search(whatErinLikes);

            if (matchingGuitar.Count != 0)
            {
                Console.WriteLine("Erin, you might like these guitar:");
                for (int i = 0; i < matchingGuitar.Count; i++)
                {
                    Guitar guitar = matchingGuitar[i];
                    Console.WriteLine(" We have a " +
                                      guitar.Builder + " " + guitar.Model + " " +
                                      guitar.Type + " guitar:\n  " +
                                      guitar.BackWood + " back and sides,\n  " +
                                      guitar.TopWood + " top.\n You can have it for only $" +
                                      guitar.Price + "!\n ----");
                }
            }
            else
            {
                Console.WriteLine("Sorry, Erin, we have nothing for you.");
            }
            Console.ReadKey();
        }
Exemplo n.º 2
0
        public void addGuitar(string serialNumber, double price, Builder_Enum builder, string model, Type_Enum type,
                              Wood_Enum backWood, Wood_Enum topWood)
        {
            Guitar guitar = new Guitar(serialNumber, price, builder, model, type, backWood, topWood);

            guitars.Add(guitar);
        }
Exemplo n.º 3
0
        public void Add(string serialNumber, double price, Builder_Enum builder, string model, Type_Enum type,
                        Wood_Enum backWood, Wood_Enum topWood, String_Enum numString)
        {
            GuitarSpec guitarSpec = new GuitarSpec(builder, model, type, backWood, topWood, numString);
            Guitar     guitar     = new Guitar(serialNumber, price, guitarSpec);

            guitars.Add(guitar);
        }
Exemplo n.º 4
0
 public Guitar GetGuitar(string serialNumber)
 {
     for (int i = 0; i < guitars.Count; i++)
     {
         Guitar guitar = guitars[i];
         if (guitar.SerialNumber.Equals(serialNumber))
         {
             return(guitar);
         }
     }
     return(null);
 }
Exemplo n.º 5
0
        public List <Guitar> Search(GuitarSpec searchSpec)
        {
            List <Guitar> matchGuitar = new List <Guitar>();

            for (int i = 0; i < guitars.Count; i++)
            {
                Guitar guitar = guitars[i];
                //使用反射获取所有的属性,分别进入这个match进行比较,最后得出结果。
                PropertyInfo[] pis  = GetProperties(searchSpec);
                PropertyInfo[] pis2 = GetProperties(guitar.Spec);
                //反射比较所有的属性
                //目前暂时存在7个属性
                GetPropertyValues(pis);
                GetPropertyValues(pis2);

                //解决方法
                //1.泛型match + 委托
                //2.用反射获取所有的属性+委托构造一个方法的比较+获取一个类对象中的所有的属性的数值

                //一种方法就是直接构建一个泛型比较,但是同样需要获取整个基础的属性进行比较。
                //另外一种方法就是,直接获取所有属性进行比较,但是目前遇到的问题就是属性的值无法返回。。。。。


                //Builder_Enum builder = searchSpec.Builder;
                //if (builder != guitar.Spec.Builder)
                //    continue;

                //string model = searchSpec.Model.ToLower();
                //if ((model != null) && (!model.Equals("")) &&
                //    (!model.Equals(guitar.Spec.Model.ToLower())))
                //    continue;

                //Type_Enum type = searchSpec.Type;
                //if (type != guitar.Spec.Type)
                //    continue;

                //Wood_Enum backWood = searchSpec.BackWood;
                //if (backWood != guitar.Spec.BackWood)
                //    continue;

                //Wood_Enum topWood = searchSpec.TopWood;
                //if (topWood != guitar.Spec.TopWood)
                //    continue;
            }
            return(matchGuitar);
        }
Exemplo n.º 6
0
        public List <Guitar> search(GuitarSpec searchSpec)
        {
            List <Guitar> matchGuitar = new List <Guitar>();

            for (int i = 0; i < guitars.Count; i++)
            {
                Guitar guitar = guitars[i];
                //使用反射获取所有的属性,分别进入这个match进行比较,最后得出结果。
                PropertyInfo[] pis  = GetProperties(searchSpec);
                PropertyInfo[] pis2 = GetProperties(guitar.Spec);
                //反射比较所有的属性
                foreach (object item in pis)
                {
                    //这里还出现了大问题。。。。
                    Console.WriteLine(pis.GetValue());
                }

                //解决方法
                //1.泛型match + 委托
                //2.用反射获取所有的属性+委托构造一个方法的比较+获取一个类对象中的所有的属性的数值


                //Builder_Enum builder = searchSpec.Builder;
                //if (builder != guitar.Spec.Builder)
                //    continue;

                //string model = searchSpec.Model.ToLower();
                //if ((model != null) && (!model.Equals("")) &&
                //    (!model.Equals(guitar.Spec.Model.ToLower())))
                //    continue;

                //Type_Enum type = searchSpec.Type;
                //if (type != guitar.Spec.Type)
                //    continue;

                //Wood_Enum backWood = searchSpec.BackWood;
                //if (backWood != guitar.Spec.BackWood)
                //    continue;

                //Wood_Enum topWood = searchSpec.TopWood;
                //if (topWood != guitar.Spec.TopWood)
                //    continue;
            }
            return(matchGuitar);
        }
Exemplo n.º 7
0
        public List <Guitar> Search(GuitarSpec searchSpec)
        {
            List <Guitar> matchGuitar = new List <Guitar>();

            for (int i = 0; i < guitars.Count; i++)
            {
                Guitar       guitar  = guitars[i];
                Builder_Enum builder = searchSpec.Builder;
                if (builder != guitar.Spec.Builder)
                {
                    continue;
                }
                string model = searchSpec.Model.ToString();
                if ((model != null) && (!model.Equals("")) &&
                    (!model.Equals(guitar.Spec.Model.ToLower())))
                {
                    continue;
                }
                Type_Enum type = searchSpec.Type;
                if (type != guitar.Spec.Type)
                {
                    continue;
                }
                Wood_Enum backWood = searchSpec.BackWood;
                if (backWood != guitar.Spec.BackWood)
                {
                    continue;
                }
                Wood_Enum topWood = searchSpec.TopWood;
                if (topWood != guitar.Spec.TopWood)
                {
                    continue;
                }
                String_Enum numString = searchSpec.NumString;
                if (numString != guitar.Spec.NumString)
                {
                    continue;
                }
                matchGuitar.Add(guitar);
            }
            return(matchGuitar);
        }
Exemplo n.º 8
0
        public void addGuitar(string serialNumber, double price, GuitarSpec guitarSpec)
        {
            Guitar guitar = new Guitar(serialNumber, price, guitarSpec);

            guitars.Add(guitar);
        }