예제 #1
0
        private Flower CreateFlower(DataRow src)
        {
            Flower dest = Flower.CreateFlower(src[FLOWER_NAME_FIELD].ToString());

            dest.Price    = int.Parse(src[FLOWER_PRICE_FIELD].ToString());
            dest.Currency = (Currency)Enum.Parse(typeof(Currency), src[FLOWER_CURRENCY_FIELD].ToString());
            dest.Colour   = (Colour)Enum.Parse(typeof(Colour), src[FLOWER_COLOUR_FIELD].ToString());
            return(dest);
        }
예제 #2
0
        private Flower CreateFlowerFromFileString(string[] values, string[] headers)
        {
            Flower flower = null;

            for (int i = 0; i < values.Length; i++)
            {
                string value  = values[i];
                string header = headers[i];

                switch (header)
                {
                case "Name":
                    flower = Flower.CreateFlower(value);
                    break;

                case "Price":
                    if (flower == null)
                    {
                        throw new ArgumentOutOfRangeException("Header 'Name' must be the first in file headers not 'Price'");
                    }

                    flower.Price = int.Parse(value);
                    break;

                case "Currency":
                    if (flower == null)
                    {
                        throw new ArgumentOutOfRangeException("Header 'Name' must be the first in file headers not 'Currency'");
                    }

                    flower.Currency = (Currency)Enum.Parse(typeof(Currency), value);
                    break;

                case "Colour":
                    if (flower == null)
                    {
                        throw new ArgumentOutOfRangeException("Header 'Name' must be the first in file headers not 'Colour'");
                    }

                    flower.Colour = (Colour)Enum.Parse(typeof(Colour), value);
                    break;

                default:
                    throw new FileFormatException(string.Format("Incorrect file format exception. Unexpected file column header: {0}", value));
                }
            }

            return(flower);
        }