comparison Implab.ServiceHost/Unity/InjectionValueBuilder.cs @ 278:6691aff01de1 v3

Implab: added XmlDefaultSeializer (SerializersPool is now obsolete) Implab.ServiceHost: rewritten TypeReference (added support for nested types), stable API
author cin
date Thu, 03 May 2018 09:59:44 +0300
parents 963b17c275be
children 8714471e8d78
comparison
equal deleted inserted replaced
277:963b17c275be 278:6691aff01de1
5 using System.Xml.Serialization; 5 using System.Xml.Serialization;
6 using Unity.Injection; 6 using Unity.Injection;
7 7
8 namespace Implab.ServiceHost.Unity { 8 namespace Implab.ServiceHost.Unity {
9 9
10 public class InjectionValueBuilder { 10 public class InjectionParameterBuilder {
11 11
12 readonly TypeResolver m_resolver; 12 readonly TypeResolver m_resolver;
13 13
14 public Type DefaultType { get; private set; } 14 public Type DefaultType { get; private set; }
15 15
24 24
25 return new InjectionParameter(ValueType, null); 25 return new InjectionParameter(ValueType, null);
26 } 26 }
27 } 27 }
28 28
29 internal InjectionValueBuilder(TypeResolver resolver, Type defaultType) { 29 internal InjectionParameterBuilder(TypeResolver resolver, Type defaultType) {
30 m_resolver = resolver; 30 m_resolver = resolver;
31 DefaultType = defaultType; 31 DefaultType = defaultType;
32 } 32 }
33 33
34 public Type ResolveInjectedValueType(string typeSpec) { 34 public Type ResolveInjectedValueType(string typeSpec) {
35 if (string.IsNullOrEmpty(typeSpec)) { 35 if (string.IsNullOrEmpty(typeSpec)) {
36 if (DefaultType == null) 36 if (DefaultType == null)
37 throw new Exception("The type must be specified"); 37 throw new Exception("The type must be specified");
38 return DefaultType; 38 return DefaultType;
39 } 39 }
40 return m_resolver.Resolve(typeSpec); 40 return m_resolver.Resolve(typeSpec, true);
41 } 41 }
42 42
43 public Type ResolveType(string typeSpec) { 43 public Type ResolveType(string typeSpec) {
44 return m_resolver.Resolve(typeSpec); 44 return m_resolver.Resolve(typeSpec, true);
45 } 45 }
46 46
47 public void SetValue(Type type, object value) { 47 public void SetValue(Type type, object value) {
48 ValueType = type; 48 ValueType = type;
49 Value = value; 49 Value = value;
73 if (itemsType == null) 73 if (itemsType == null)
74 throw new Exception("Failed to determine array elements type"); 74 throw new Exception("Failed to determine array elements type");
75 75
76 InjectionParameterValue[] injections = (arrayParameter.Items ?? new InjectionParameterElement[0]) 76 InjectionParameterValue[] injections = (arrayParameter.Items ?? new InjectionParameterElement[0])
77 .Select(x => { 77 .Select(x => {
78 var builder = new InjectionValueBuilder(m_resolver, itemsType); 78 var builder = new InjectionParameterBuilder(m_resolver, itemsType);
79 x.Visit(builder); 79 x.Visit(builder);
80 return builder.Injection; 80 return builder.Injection;
81 }) 81 })
82 .ToArray(); 82 .ToArray();
83 83
84 var array = itemsType.IsGenericParameter ? (object)new GenericResolvedArrayParameter(itemsType.Name, injections) : new ResolvedArrayParameter(itemsType, injections); 84 var array = itemsType.IsGenericParameter ?
85 (object)new GenericResolvedArrayParameter(itemsType.Name, injections) :
86 new ResolvedArrayParameter(itemsType, injections);
87
85 ValueType = arrayType; 88 ValueType = arrayType;
86 Value = array; 89 Value = array;
87 } 90 }
88 } 91 }
89 } 92 }