annotate Implab.ServiceHost/Unity/SerializedParameterElement.cs @ 279:8714471e8d78 v3

Container configuration cleanup, RC2
author cin
date Fri, 04 May 2018 18:12:42 +0300
parents 6691aff01de1
children e0916ddc9950
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
274
22629bf26121 Unity xml configuration, alpha2
cin
parents: 273
diff changeset
1 using System;
271
d4d437ec4483 Working on Unity xml configuration
cin
parents: 270
diff changeset
2 using System.Xml;
d4d437ec4483 Working on Unity xml configuration
cin
parents: 270
diff changeset
3 using System.Xml.Schema;
d4d437ec4483 Working on Unity xml configuration
cin
parents: 270
diff changeset
4 using System.Xml.Serialization;
d4d437ec4483 Working on Unity xml configuration
cin
parents: 270
diff changeset
5
270
ade80d94dfb5 Working on Unity container xml configuration
cin
parents:
diff changeset
6 namespace Implab.ServiceHost.Unity
ade80d94dfb5 Working on Unity container xml configuration
cin
parents:
diff changeset
7 {
277
963b17c275be Refactoring
cin
parents: 275
diff changeset
8 public class SerializedParameterElement : InjectionParameterElement {
273
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents: 272
diff changeset
9 [XmlAttribute("href")]
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents: 272
diff changeset
10 public string Location { get; set; }
271
d4d437ec4483 Working on Unity xml configuration
cin
parents: 270
diff changeset
11
d4d437ec4483 Working on Unity xml configuration
cin
parents: 270
diff changeset
12 [XmlAnyElement]
d4d437ec4483 Working on Unity xml configuration
cin
parents: 270
diff changeset
13 public XmlElement[] Content { get; set; }
272
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
14
274
22629bf26121 Unity xml configuration, alpha2
cin
parents: 273
diff changeset
15 public XmlReader GetReader() {
22629bf26121 Unity xml configuration, alpha2
cin
parents: 273
diff changeset
16 if (!string.IsNullOrEmpty(Location))
22629bf26121 Unity xml configuration, alpha2
cin
parents: 273
diff changeset
17 return XmlReader.Create(Location);
22629bf26121 Unity xml configuration, alpha2
cin
parents: 273
diff changeset
18 if (Content != null && Content.Length > 0)
22629bf26121 Unity xml configuration, alpha2
cin
parents: 273
diff changeset
19 return Content[0].CreateNavigator().ReadSubtree();
22629bf26121 Unity xml configuration, alpha2
cin
parents: 273
diff changeset
20
22629bf26121 Unity xml configuration, alpha2
cin
parents: 273
diff changeset
21 throw new Exception("No content found, expected XML document");
22629bf26121 Unity xml configuration, alpha2
cin
parents: 273
diff changeset
22 }
22629bf26121 Unity xml configuration, alpha2
cin
parents: 273
diff changeset
23
278
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
24 public override void Visit(InjectionParameterBuilder builder) {
277
963b17c275be Refactoring
cin
parents: 275
diff changeset
25 var type = builder.ResolveInjectedValueType(TypeName);
963b17c275be Refactoring
cin
parents: 275
diff changeset
26
963b17c275be Refactoring
cin
parents: 275
diff changeset
27 var serializer = new XmlSerializer(type);
963b17c275be Refactoring
cin
parents: 275
diff changeset
28 using(var reader = GetReader())
963b17c275be Refactoring
cin
parents: 275
diff changeset
29 builder.SetValue(type, serializer.Deserialize(reader));
963b17c275be Refactoring
cin
parents: 275
diff changeset
30
272
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
31 }
270
ade80d94dfb5 Working on Unity container xml configuration
cin
parents:
diff changeset
32 }
ade80d94dfb5 Working on Unity container xml configuration
cin
parents:
diff changeset
33 }