当前位置: 首页>>代码示例>>C#>>正文


C# Recipe.Add方法代码示例

本文整理汇总了C#中Recipe.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Recipe.Add方法的具体用法?C# Recipe.Add怎么用?C# Recipe.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Recipe的用法示例。


在下文中一共展示了Recipe.Add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateRecipe

        /// <summary>
        /// Creates a new recipe
        /// </summary>
        /// <returns>The recipe or null if aborted</returns>
        private static Recipe CreateRecipe()
        {
            Console.Clear();
            RecipeView.RenderHeader("          Nytt recept          ");
            string name = ReadRecipeName();
            if (name == null) {
                return null;
            }

            Recipe recipe = new Recipe(name);

            List<Ingredient> ingredients = ReadIngredients();
            if (ingredients == null) {
                return null;
            }
            foreach (Ingredient ingredient in ingredients) {
                recipe.Add(ingredient);
            }

            List<string> directions = ReadDirections();
            if (directions == null) {
                return null;
            }
            foreach (string direction in directions) {
                recipe.Add(direction);
            }

            return recipe;
        }
开发者ID:re222dv,项目名称:1DV402-C-sharp,代码行数:33,代码来源:Program.cs

示例2: Load

        public virtual void Load()
        {
            List<IRecipe> recipesList = new List<IRecipe>();
            RecipeReadStatus status = new RecipeReadStatus();
            Recipe recipe = null;

            using (StreamReader loadedRecipe = new StreamReader(_path))
            {
                string line;
                while ((line = loadedRecipe.ReadLine()) != null)
                {
                    if (line == SectionRecipe)
                    {
                        status = RecipeReadStatus.New;
                    }
                    else if (line == SectionIngredients)
                    {
                        status = RecipeReadStatus.Ingredient;
                    }
                    else if (line == SectionInstructions)
                    {
                        status = RecipeReadStatus.Instruction;
                    }
                    else
                    {
                        switch (status)
                            {
                                case RecipeReadStatus.Indefinite:
                                    throw new FileFormatException();
                                case RecipeReadStatus.New:
                                    recipe = new Recipe(line);
                                    recipesList.Add(recipe);
                                    break;
                                case RecipeReadStatus.Ingredient:
                                    string[] ingredientArray = line.Split(new char[] { ';' } );
                                    if (ingredientArray.Length != 3)
                                    {
                                        throw new FileFormatException();
                                    }
                                    Ingredient ingredient = new Ingredient();
                                    ingredient.Amount = ingredientArray[0];
                                    ingredient.Measure = ingredientArray[1];
                                    ingredient.Name = ingredientArray[2];
                                    recipe.Add(ingredient);
                                    break;
                                case RecipeReadStatus.Instruction:
                                    if (line.Length > 0)
                                    {
                                        recipe.Add(line);
                                    }
                                    break;
                            }
                    }
                    recipesList.Sort();
                    _recipes = recipesList;
                    IsModified = false;
                    OnRecipesChanged(EventArgs.Empty);
                }
            }
        }
开发者ID:OskarKlintrotSkolarbeteWP14,项目名称:3-1-recept-pa-fil,代码行数:60,代码来源:RecipeRepository.cs

示例3: Load

        /// <summary>
        /// Loads recipes from the file specified at Path
        /// </summary>
        /// <returns>A list of recipes</returns>
        public List<Recipe> Load()
        {
            RecipeReadStatus status = RecipeReadStatus.Indefinite;
            string[] lines = System.IO.File.ReadAllLines(Path);
            Recipe recipe = null;
            List<Recipe> recepies = new List<Recipe>();

            foreach (string line in lines) {
                if (String.IsNullOrWhiteSpace(line)) {
                    continue;
                } else if (line == "[Recept]") {
                    status = RecipeReadStatus.New;
                    continue;
                } else if (line == "[Ingredienser]") {
                    status = RecipeReadStatus.Ingredient;
                    continue;
                } else if (line == "[Instruktioner]") {
                    status = RecipeReadStatus.Direction;
                    continue;
                }

                try {
                    switch (status) {
                        case RecipeReadStatus.New:
                            recipe = new Recipe(line);
                            recepies.Add(recipe);
                            break;
                        case RecipeReadStatus.Ingredient:
                            Ingredient i = new Ingredient();
                            string[] parts = line.Split(';');

                            if (parts.Length != 3) {
                                throw new Exception("bad file format");
                            }

                            i.Amount = parts[0];
                            i.Measure = parts[1];
                            i.Name = parts[2];

                            recipe.Add(i);
                            break;
                        case RecipeReadStatus.Direction:
                            recipe.Add(line);
                            break;
                        default:
                            throw new Exception("bad file format");
                    }
                } catch (NullReferenceException) {
                    throw new Exception("bad file format");
                }
            }

            recepies.Sort();

            return recepies;
        }
开发者ID:re222dv,项目名称:1DV402-C-sharp,代码行数:60,代码来源:RecipeRepository.cs


注:本文中的Recipe.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。