Exemple #1
0
        public static IEnumerable<Product> LoadFrom()
        {
            List<Product> products = new List<Product>();

            using (StreamReader reader = new StreamReader(typeof(Product).Assembly.GetManifestResourceStream("Fidely.Demo.GettingStarted.WPF.Products.csv")))
            {
                string[] lines = reader.ReadToEnd().Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string line in lines)
                {
                    string csv = (line.Contains('#')) ? line.Substring(0, line.IndexOf('#')) : line;
                    if (String.IsNullOrWhiteSpace(csv))
                    {
                        continue;
                    }

                    string[] values = csv.Split(',');
                    if (values.Length != 4)
                    {
                        continue;
                    }

                    Product product = new Product();
                    product.ProductID = Int32.Parse(values[0]);
                    product.Name = String.IsNullOrWhiteSpace(values[1]) ? null : values[1].Trim();
                    product.ListPrice = Decimal.Parse(values[2]);
                    product.SellStartDate = DateTime.Parse(values[3]);

                    products.Add(product);
                }
            }

            return products;
        }
 public ProductViewModel(Product model)
 {
     this.model = model;
 }