public bool Matches(InstrumentSpec otherspec) { foreach (KeyValuePair <string, object> property in otherspec._properties) { if ( (this._properties.ContainsKey(property.Key) && this._properties.ContainsValue(property.Value))) { return(true); } } return(false); }
//public Instrument Get(string instrumentName) //{ // return0; //} public List <Instrument> Search(InstrumentSpec searchspec) { List <Instrument> MatchingInstrument = new List <Instrument>(); foreach (Instrument instrument in _inventory) { if (instrument.Spec.Matches(searchspec)) { MatchingInstrument.Add(instrument); } } return(MatchingInstrument); }
static void Main(string[] args) { Inventory inventory = new Inventory(); InitializeInventory(inventory); Dictionary <string, object> properties = new Dictionary <string, object>(); // properties.Add("instrumentType", InstrumentType.GUITAR); properties.Add("builder", Builder.FENDER); properties.Add("model", "CJ"); //properties.Add("numString", 6); //properties.Add("topWood", Wood.INDIAN_ROSEWOOD); //properties.Add("backWood", Wood.SITKA); InstrumentSpec clientSpec = new InstrumentSpec(properties); List <Instrument> matchingInstrument = inventory.Search(clientSpec); if (matchingInstrument.Count >= 0) { Console.WriteLine("you might like these Instrument:"); foreach (Instrument instrument in matchingInstrument) { InstrumentSpec spec = instrument.Spec; // Console.WriteLine("We have a " + spec.GetProperty("instrumentType") + " with follwing Properties "); foreach (var j in spec.Properties.Keys) { string propertyName = Convert.ToString(j); //if (propertyName.Equals("instrumentType") || propertyName.Equals("instrumentType1")) //{ // continue; //} Console.WriteLine(" " + propertyName + " :" + spec.GetProperty(propertyName)); } Console.WriteLine("You can have this " + spec.GetProperty("instrumentType") + " $" + instrument.Price + "\n----"); } } else { Console.WriteLine("Sorry,we have nothing fo you"); } }
public void AddInstrument(string serialNumber, double price, InstrumentSpec spec) //Builder builder, string model, Type type, Wood backwood, Wood topwood) { Instrument instrument = new Instrument(serialNumber, price, spec); _inventory.Add(instrument); }
public Instrument(string serialNumber, double price, InstrumentSpec spec) { _serialNumber = serialNumber; _price = price; _spec = spec; }