private static void PopulateProperties(ref Band band, BandData data, Genre genre) { band.Name = data.Name; band.YearFormed = data.YearFormed; band.Members = data.Members; band.Albums = data.Albums; band.Genre = genre; }
public static IndieBand GenerateNew(BandData data) { IndieBand band = new IndieBand(); band.Name = data.Name; band.YearFormed = data.YearFormed; band.Members = data.Members; band.Albums = data.Albums; return(band); }
public static Band MakeNewBand(Genre genre, BandData data) { Band band = new RockBand(); // it doesn't matter what type of band we use, // we just need to instantiate the 'band' object to a non-abstract type CastToGenre(ref band, genre); PopulateProperties(ref band, data, genre); return(band); }
// --------------------------------------------------------------------------------------------------------------------------------------------------------- #endregion #region Error Handling // --------------------------------------------------------------------------------------------------------------------------------------------------------- public static bool Validate(BandData data) // tests to see if any of the bands data is null { PropertyInfo[] properties = data.GetType().GetProperties(); foreach (var property in properties) { if (property == null) { return(false); } } return(true); }
public MainWindow() { #region JSON stuf -- @todo cleanup, later //bool isReal = File.Exists(@"C:\Users\David\Desktop\bands.json"); //string json = File.ReadAllText(@"C:\Users\David\Desktop\bands.json"); //BandDB[] jsonBands = JsonConvert.DeserializeObject<BandDB[]>(json); //RockBand rockBand = new RockBand(jsonBands[1]); //PopBand popBand = new PopBand(jsonBands[0]); #endregion #region temp stuff Album album1 = new Album { Name = "first", YearReleased = Album.GenerateReleaseYear(), SalesCount = 10000 }; Album[] band1Albums = new Album[] { album1, album1 }; BandData band1Data = new BandData { Name = "thiswon", YearFormed = 1984, Members = new string[] { "bob", "alan" }, Albums = band1Albums }; RockBand band1 = RockBand.GenerateNew(band1Data); PopBand band2 = PopBand.GenerateNew(band1Data); IndieBand band3 = IndieBand.GenerateNew(band1Data); PopBand band4 = BandFactory.MakeNewBand(Genre.Pop, band1Data) as PopBand; RockBand band5 = BandFactory.MakeNewBand(Genre.Rock, band1Data) as RockBand; IndieBand band6 = BandFactory.MakeNewBand(Genre.Indie, band1Data) as IndieBand; PopBand band7 = BandFactory.MakeNewBand(Genre.Pop, band1Data) as PopBand; RockBand band8 = BandFactory.MakeNewBand(Genre.Rock, band1Data) as RockBand; IndieBand band9 = BandFactory.MakeNewBand(Genre.Indie, band1Data) as IndieBand; #endregion Band[] bands = { band1, band2, band3, band4, band5, band6, band7, band8, band9 }; Array.Sort(bands); InitializeComponent(); //textBoxFormed.Text = json; listBoxBands.ItemsSource = bands; comboBoxGenres.ItemsSource = Enum.GetNames(typeof(Genre)); }