本文整理汇总了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;
}
示例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);
}
}
}
示例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;
}