Mercurial > pub > ImplabNet
annotate Implab.ServiceHost/Unity/SerializedParameterElement.cs @ 281:e0916ddc9950 v3 tip
code cleanup and refactoring
| author | cin |
|---|---|
| date | Fri, 01 Jun 2018 21:35:24 +0300 |
| parents | 6691aff01de1 |
| children |
| rev | line source |
|---|---|
| 274 | 1 using System; |
| 271 | 2 using System.Xml; |
| 3 using System.Xml.Schema; | |
| 4 using System.Xml.Serialization; | |
| 5 | |
| 270 | 6 namespace Implab.ServiceHost.Unity |
| 7 { | |
| 281 | 8 public class SerializedParameterElement : AbstractInjectionParameter { |
|
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 | 11 |
| 12 [XmlAnyElement] | |
| 13 public XmlElement[] Content { get; set; } | |
| 272 | 14 |
| 274 | 15 public XmlReader GetReader() { |
| 16 if (!string.IsNullOrEmpty(Location)) | |
| 17 return XmlReader.Create(Location); | |
| 18 if (Content != null && Content.Length > 0) | |
| 19 return Content[0].CreateNavigator().ReadSubtree(); | |
| 20 | |
| 21 throw new Exception("No content found, expected XML document"); | |
| 22 } | |
| 23 | |
|
278
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
277
diff
changeset
|
24 public override void Visit(InjectionParameterBuilder builder) { |
| 277 | 25 var type = builder.ResolveInjectedValueType(TypeName); |
| 26 | |
| 27 var serializer = new XmlSerializer(type); | |
| 28 using(var reader = GetReader()) | |
| 29 builder.SetValue(type, serializer.Deserialize(reader)); | |
| 30 | |
| 272 | 31 } |
| 270 | 32 } |
| 33 } |
