annotate Implab.ServiceHost/Unity/SerializedElement.cs @ 274:22629bf26121 v3

Unity xml configuration, alpha2
author cin
date Fri, 27 Apr 2018 04:47:52 +0300
parents 79110a16cab7
children 6fefd5811b9b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
273
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents:
diff changeset
1 using System;
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents:
diff changeset
2 using System.Xml;
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents:
diff changeset
3 using System.Xml.Serialization;
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents:
diff changeset
4
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents:
diff changeset
5 namespace Implab.ServiceHost.Unity
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents:
diff changeset
6 {
274
22629bf26121 Unity xml configuration, alpha2
cin
parents: 273
diff changeset
7 public class SerializedElement : AbstractRegistration, ISerializedValue {
273
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents:
diff changeset
8 [XmlAttribute("href")]
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents:
diff changeset
9 public string Location { get; set; }
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents:
diff changeset
10
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents:
diff changeset
11 [XmlAttribute("serializedType")]
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents:
diff changeset
12 public string SerializedType { get; set; }
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents:
diff changeset
13
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents:
diff changeset
14
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents:
diff changeset
15 [XmlAnyElement]
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents:
diff changeset
16 public XmlElement[] Content { get; set; }
274
22629bf26121 Unity xml configuration, alpha2
cin
parents: 273
diff changeset
17
22629bf26121 Unity xml configuration, alpha2
cin
parents: 273
diff changeset
18 string ISerializedValue.TypeName {
22629bf26121 Unity xml configuration, alpha2
cin
parents: 273
diff changeset
19 get {
22629bf26121 Unity xml configuration, alpha2
cin
parents: 273
diff changeset
20 return string.IsNullOrEmpty(SerializedType) ? RegistrationType : SerializedType;
22629bf26121 Unity xml configuration, alpha2
cin
parents: 273
diff changeset
21 }
22629bf26121 Unity xml configuration, alpha2
cin
parents: 273
diff changeset
22 }
22629bf26121 Unity xml configuration, alpha2
cin
parents: 273
diff changeset
23
22629bf26121 Unity xml configuration, alpha2
cin
parents: 273
diff changeset
24 public override void Visit(ContainerBuilder context) {
273
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents:
diff changeset
25 context.Visit(this);
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents:
diff changeset
26 }
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents:
diff changeset
27
274
22629bf26121 Unity xml configuration, alpha2
cin
parents: 273
diff changeset
28 public XmlReader GetReader() {
22629bf26121 Unity xml configuration, alpha2
cin
parents: 273
diff changeset
29 if (!string.IsNullOrEmpty(Location))
22629bf26121 Unity xml configuration, alpha2
cin
parents: 273
diff changeset
30 return XmlReader.Create(Location);
22629bf26121 Unity xml configuration, alpha2
cin
parents: 273
diff changeset
31 if (Content != null && Content.Length > 0)
22629bf26121 Unity xml configuration, alpha2
cin
parents: 273
diff changeset
32 return Content[0].CreateNavigator().ReadSubtree();
273
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents:
diff changeset
33
274
22629bf26121 Unity xml configuration, alpha2
cin
parents: 273
diff changeset
34 throw new Exception("No content found, expected XML document");
273
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents:
diff changeset
35 }
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents:
diff changeset
36 }
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents:
diff changeset
37 }