Mercurial > pub > ImplabNet
diff 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 |
line wrap: on
line diff
--- a/Implab.ServiceHost/Unity/SerializedElement.cs Thu Apr 26 19:35:01 2018 +0300 +++ b/Implab.ServiceHost/Unity/SerializedElement.cs Fri Apr 27 04:47:52 2018 +0300 @@ -4,7 +4,7 @@ namespace Implab.ServiceHost.Unity { - public class SerializedElement : AbstractRegistration { + public class SerializedElement : AbstractRegistration, ISerializedValue { [XmlAttribute("href")] public string Location { get; set; } @@ -14,25 +14,24 @@ [XmlAnyElement] public XmlElement[] Content { get; set; } - - public override void Visit(ContainerContext context) { + + string ISerializedValue.TypeName { + get { + return string.IsNullOrEmpty(SerializedType) ? RegistrationType : SerializedType; + } + } + + public override void Visit(ContainerBuilder context) { context.Visit(this); } - public virtual Type ResolveSerializedType(ContainerContext context) { - if(string.IsNullOrEmpty(SerializedType)) - return ResolveRegistrationType(context); - return context.Resolve(SerializedType); - } + public XmlReader GetReader() { + if (!string.IsNullOrEmpty(Location)) + return XmlReader.Create(Location); + if (Content != null && Content.Length > 0) + return Content[0].CreateNavigator().ReadSubtree(); - public virtual object GetValue(ContainerContext context) { - var type = ResolveRegistrationType(context); - if (Content == null || Content.Length == 0) - return Safe.CreateDefaultValue(type); - - var serializer = new XmlSerializer(type); - using(var reader = Content[0].CreateNavigator().ReadSubtree()) - return serializer.Deserialize(reader); + throw new Exception("No content found, expected XML document"); } } } \ No newline at end of file