Esempio n. 1
0
        static void Main(string[] args)
        {
            // Set up Rick's guitar inventory
            Inventory inventory = new Inventory();

            InitializeInventory(inventory);

            IDictionary properties = new Hashtable();

            properties.Add("builder", Builder.GIBSON);
            properties.Add("backWood", Wood.MAPLE);
            InstrumentSpec clientSpec = new InstrumentSpec(properties);

            List <Instrument> matchingInstruments = inventory.Search(clientSpec);

            if (matchingInstruments != null && matchingInstruments.Count > 0)
            {
                Console.WriteLine("---------------------------------\n");
                Console.WriteLine("Erin, you might like these instruments:\n");

                foreach (var instrument in matchingInstruments)
                {
                    InstrumentSpec spec = instrument.InstrumentSpec;

                    Console.WriteLine($"We have a {spec.GetProperty("instrumentType")} with the following properties:");

                    foreach (DictionaryEntry property in spec.GetAllProperties())
                    {
                        string propertyName = (string)property.Key;
                        if (propertyName.Equals("instrumentType"))
                        {
                            continue;
                        }
                        Console.WriteLine($"   {propertyName}: {spec.GetProperty(propertyName)}");
                    }

                    Console.WriteLine($"  You can have this {spec.GetProperty("instrumentType")} for ${instrument.Price}\n----");

                    Console.WriteLine("---------------------------------\n");
                }
            }
            else
            {
                Console.WriteLine("Sorry, Erin, we have nothing for you.");
            }

            Console.WriteLine("\n");
        }
        public bool Matches(InstrumentSpec otherSpec)
        {
            foreach (DictionaryEntry property in otherSpec.GetAllProperties())
            {
                string propertyName = (string)property.Key;
                if (!_properties[propertyName].Equals(otherSpec.GetProperty(propertyName)))
                {
                    return(false);
                }
            }

            return(true);
        }