Serialize test

This commit is contained in:
Arti Zirk 2017-02-01 17:35:17 +02:00
parent bc7fe5ffae
commit e3a3880d62
1 changed files with 30 additions and 2 deletions

View File

@ -1,14 +1,42 @@
using System; using System;
using System.Collections.Generic;
using System.Xml.Linq; using System.Xml.Linq;
using System.Xml.Serialization;
namespace vr21 namespace vr21
{ {
public class Receipe
{
public string Name;
public List<Ingredient> Ingredients;
public Receipe()
{
Ingredients = new List<Ingredient>();
}
}
public class Ingredient
{
public string Name;
public int Count;
public string Unit;
}
class Program class Program
{ {
private static string _xmllocation = @"..\..\..\XMLRecipe.xml"; private static string _xmllocation = @"..\..\..\XMLRecipe.xml";
static void Main(string[] args) static void Main(string[] args)
{ {
writeReceipesInformation(); Ingredient kartul = new Ingredient() {Name = "Kartul", Count = 500, Unit = "g"};
Receipe r = new Receipe() {Name="Supp"};
r.Ingredients.Add(kartul);
r.Ingredients.Add(kartul);
List<Receipe> l = new List<Receipe>();
l.Add(r);
l.Add(r);
XmlSerializer x = new XmlSerializer(l.GetType());
x.Serialize(Console.Out, l);
//writeReceipesInformation();
Console.ReadKey(); Console.ReadKey();
} }