annotate Implab.ServiceHost/Unity/ContainerElement.cs @ 272:9d1cca834b05 v3

preview version of Unity xml configuration
author cin
date Thu, 26 Apr 2018 03:14:54 +0300
parents d4d437ec4483
children 79110a16cab7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
267
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
1 using Implab.Xml;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
2 using System.Collections.Generic;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
3 using System.Xml;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
4 using System.Xml.Schema;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
5 using System.Xml.Serialization;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
6
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
7 namespace Implab.ServiceHost.Unity {
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
8 [XmlRoot("container", Namespace = Schema.ContainerConfigurationNamespace)]
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
9 public class ContainerElement : IXmlSerializable {
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
10
270
ade80d94dfb5 Working on Unity container xml configuration
cin
parents: 269
diff changeset
11 public List<IConfigurationElement> Items {get; set; } = new List<IConfigurationElement>();
267
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
12
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
13 public XmlSchema GetSchema() {
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
14 return null;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
15 }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
16
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
17 public void ReadXml(XmlReader reader) {
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
18 while(reader.Read() && reader.NodeType != XmlNodeType.EndElement) {
269
ff581cff7003 Working on Unity container xml configuration
cin
parents: 267
diff changeset
19 var registration = ConfigurationSchema.Default.Deserialize<IConfigurationElement>(reader);
270
ade80d94dfb5 Working on Unity container xml configuration
cin
parents: 269
diff changeset
20 Items.Add(registration);
267
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
21 }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
22 }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
23
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
24 public void WriteXml(XmlWriter writer) {
271
d4d437ec4483 Working on Unity xml configuration
cin
parents: 270
diff changeset
25 foreach(var item in Items) {
d4d437ec4483 Working on Unity xml configuration
cin
parents: 270
diff changeset
26 var serializer = new XmlSerializer(item.GetType());
d4d437ec4483 Working on Unity xml configuration
cin
parents: 270
diff changeset
27 serializer.Serialize(writer, item);
d4d437ec4483 Working on Unity xml configuration
cin
parents: 270
diff changeset
28 }
267
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
29 }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
30 }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
31 }