Guest User

Untitled

a guest
Feb 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.03 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Collections.ObjectModel;
  6. using System.IO;
  7.  
  8. namespace _1DV402.S3.L1
  9. {
  10.     enum RecipeReadStatus {Indefinite, New, Ingredient, Direction }
  11.     class RecipeRepository
  12.     {
  13.         private string _path;
  14.  
  15.         public string Path
  16.         {
  17.             get { return _path; }
  18.             set
  19.             {
  20.                 if (String.IsNullOrWhiteSpace(value))
  21.                 {
  22.                     Console.WriteLine("Strängen är tom eller innehåller mellanslag!");
  23.                 }
  24.                 _path = value;
  25.             }
  26.         }
  27.  
  28.         public RecipeRepository(string path) //Path får sitt värde i konstruktorn, skickas från LoadRecipes.
  29.         {
  30.             Path = path;
  31.  
  32.         }
  33.  
  34.        public IList<Recipe> Load()
  35.         {
  36.             List<string> LoadRecipe = new List<string>();
  37.             using(StreamReader reader = new StreamReader (this.Path))
  38.             {
  39.                 //Läs in ] då vet du att du kommer vara inne på namnet.
  40.                 //Gör en sträng av det, sen nästa gång ] kommer du vara vid ingredienserna
  41.                 //och vid varje ; sätter du ett space istället och vid varje whitespace(alltså ny rad)
  42.                 //så vet du att det kommer en ny ingrediens.
  43.                 //Använd arraynamn.Length för att kolla om den har tre delar.
  44.                 String textLine; //Används för att läsa filen.
  45.  
  46.                 while ((textLine = reader.ReadLine()) != null) //Läser filen rad för rad så länge null inte returneras.
  47.                 {
  48.                  
  49.                         textLine = reader.ReadLine(); //Läser en rad.
  50.                         string[] ingredients = textLine.Split(new string[] { ";", ";;" }, StringSplitOptions.RemoveEmptyEntries); //Delar upp i tre strängar.
  51.                    
  52.                 }
  53.             }
  54.             return //En instans av nån instans bla bla bla
  55.         }
  56.  
  57.  
  58.        
  59.        
  60.     }
  61. }
Add Comment
Please, Sign In to add comment