Exemplo n.º 1
0
        public void SerializeObjectWithDataContractSerializer()
        {
            AnimalStore            ads       = AnimalStore.AnimalDataStore();
            DataContractSerializer formatter = new DataContractSerializer(typeof(AnimalStore), new DataContractSerializerSettings()
            {
                MaxItemsInObjectGraph = 50
            });

            using (FileStream fs = new FileStream("Animal.xml", FileMode.OpenOrCreate, FileAccess.Write))
            {
                formatter.WriteObject(fs, ads);
            }
        }
Exemplo n.º 2
0
        public static AnimalStore AnimalDataStore()
        {
            AnimalStore result = new AnimalStore()
            {
                Dog = new Dog()
                {
                    AnimalId = 1, Neutered = false
                },
                Animal = new Animal()
                {
                    Age = 2, Id = 2, Name = "Doggy"
                }
            };

            return(result);
        }