2017-02-01 16:06:52 +02:00
|
|
|
|
using System;
|
2017-02-01 17:03:44 +02:00
|
|
|
|
using System.Collections;
|
2017-02-01 16:06:52 +02:00
|
|
|
|
using System.Collections.Generic;
|
2017-02-01 17:03:44 +02:00
|
|
|
|
using System.IO;
|
2017-02-01 16:06:52 +02:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-02-01 17:03:44 +02:00
|
|
|
|
using System.Xml;
|
|
|
|
|
using System.Xml.Serialization;
|
|
|
|
|
using Microsoft.SqlServer.Server;
|
2017-02-01 16:06:52 +02:00
|
|
|
|
|
|
|
|
|
namespace vr21
|
|
|
|
|
{
|
2017-02-01 17:03:44 +02:00
|
|
|
|
[XmlRoot("Recipes")]
|
|
|
|
|
public class Recipes
|
|
|
|
|
{
|
|
|
|
|
[XmlElement("Recipe")]
|
|
|
|
|
public List<Recipe> RecipeList { get; set; }
|
|
|
|
|
|
|
|
|
|
public Recipes()
|
|
|
|
|
{
|
|
|
|
|
RecipeList = new List<Recipe>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class Recipe
|
|
|
|
|
{
|
|
|
|
|
[XmlElement("Name")]
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
|
|
|
|
[XmlElement("Ingredient")]
|
|
|
|
|
public List<Ingredient> IngredientsList { get; set; }
|
|
|
|
|
|
|
|
|
|
[XmlElement("Step")]
|
|
|
|
|
public List<string> StepList { get; set; }
|
|
|
|
|
|
|
|
|
|
public Recipe()
|
|
|
|
|
{
|
|
|
|
|
IngredientsList = new List<Ingredient>();
|
|
|
|
|
StepList = new List<string>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Recipe(string name)
|
|
|
|
|
{
|
|
|
|
|
Name = name;
|
|
|
|
|
IngredientsList = new List<Ingredient>();
|
|
|
|
|
StepList = new List<string>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Recipe(string name, List<Ingredient> ingredients)
|
|
|
|
|
{
|
|
|
|
|
Name = name;
|
|
|
|
|
IngredientsList = ingredients;
|
|
|
|
|
StepList = new List<string>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class Ingredient
|
|
|
|
|
{
|
|
|
|
|
[XmlElement("Name")]
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
|
|
|
|
[XmlElement("Amount")]
|
|
|
|
|
public int Amount { get; set; }
|
|
|
|
|
|
|
|
|
|
public Ingredient(string name)
|
|
|
|
|
{
|
|
|
|
|
Name = name;
|
|
|
|
|
Amount = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Ingredient(string name, int amount)
|
|
|
|
|
{
|
|
|
|
|
Name = name;
|
|
|
|
|
Amount = amount;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-01 16:06:52 +02:00
|
|
|
|
class Program
|
|
|
|
|
{
|
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
2017-02-01 17:03:44 +02:00
|
|
|
|
var recipes = new Recipes();
|
|
|
|
|
recipes.RecipeList.Add(new Recipe("Supp"));
|
|
|
|
|
XmlSerializer serializer = new XmlSerializer(typeof(Recipes));
|
|
|
|
|
|
|
|
|
|
var xml = "";
|
|
|
|
|
|
|
|
|
|
using (var sww = new StringWriter())
|
|
|
|
|
{
|
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(sww))
|
|
|
|
|
{
|
|
|
|
|
serializer.Serialize(writer, recipes);
|
|
|
|
|
xml = sww.ToString(); // Your XML
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Console.WriteLine(xml);
|
2017-02-01 16:06:52 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|