Mercurial > pub > ImplabNet
annotate Implab.ServiceHost/Unity/TypeReference.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 |
---|---|
268 | 1 using System; |
2 using System.Linq; | |
3 using System.Text; | |
4 | |
267 | 5 namespace Implab.ServiceHost.Unity { |
278
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
6 /// <summary> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
7 /// Ссылка на тип, является абстрактной записью имени CLR типа. |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
8 /// </summary> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
9 /// <remarks> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
10 /// Ссылка на тип содержит сокращенную информацию о типе и для ее интерпретации |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
11 /// требуется некоторый контекст, который позволит превратить ее в полноценный |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
12 /// <see cref="Type"/>. Ссылки на тип позволяют записать: |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
13 /// <list> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
14 /// <item><description>общие типы, их специализации</description></item> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
15 /// <item><description>вложенные типы</description></item> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
16 /// <item><description>массивы</description></item> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
17 /// </list> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
18 /// <para> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
19 /// Для получения из ссылки на тип конкретного CLR типа используется <see cref="TypeResolver.Resolve(TypeReference, bool)"/>. |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
20 /// </para> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
21 /// <para> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
22 /// Ссылку на тип можно создать либо програмно при помощи методов <see cref="Create(string, string, int)"/>, |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
23 /// <see cref="Create(string, int)"/>, <see cref="MakeArrayType(int)"/>, <see cref="MakeGenericType(TypeReference[])"/>, |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
24 /// либо разобрав строку со спецификацией при помощи метода <see cref="Parse(string)"/>. |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
25 /// </para> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
26 /// <para> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
27 /// Спецификация ссыдки на тип имеет следующий вид <c>Name.Space.MyType+Nested{String}[][]</c>, где: |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
28 /// <list type="table"> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
29 /// <item> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
30 /// <term><c>.</c></term> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
31 /// <description>Разделяет элементы пространства имен</description> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
32 /// <item> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
33 /// <item> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
34 /// <term><c>+</c></term> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
35 /// <description>Разделяет вложенные типы</description> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
36 /// <item> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
37 /// <item> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
38 /// <term><c>[]</c>, <c>[,,,]</c></term> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
39 /// <description>Указывает на то, что тип является массивом, также указывается его размерность</description> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
40 /// <item> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
41 /// <item> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
42 /// <term><c>{}</c>, <c>{,,}</c>, <c>{Int32,String}</c></term> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
43 /// <description>Указывает на то, что тип является общим, также |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
44 /// указывается количество параметров, либо конкретные типы для |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
45 /// специализации</description> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
46 /// <item> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
47 /// </list> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
48 /// </para> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
49 /// </remarks> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
50 public abstract class TypeReference { |
268 | 51 |
278
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
52 /// <summary> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
53 /// Имя типа без дополнительных элементов, указывающих на то, что он общий или массив. |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
54 /// </summary> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
55 /// <remarks> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
56 /// Для массивов это имя его элементов. |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
57 /// </remarks> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
58 public abstract string Name { get; } |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
59 |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
60 /// <summary> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
61 /// Пространство имен в котором нахожится тип. |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
62 /// </summary> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
63 /// <remarks> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
64 /// Для вложенных типов это пространтство имен типа самого верхнего уровня, |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
65 /// для массивов - пространство имен его элементов. |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
66 /// </remarks> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
67 public abstract string Namespace { get; } |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
68 |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
69 /// <summary> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
70 /// Количество параметров общего типа. |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
71 /// </summary> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
72 /// <remarks> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
73 /// <para> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
74 /// Вложенные типы неявно получают параметры от типов в которых они объявлены, |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
75 /// данное свойство это не учитывает, возвращается только количество собственных |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
76 /// параметров. |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
77 /// </para> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
78 /// <para> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
79 /// Данное свойство используется для получения CRL имени типа. |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
80 /// </para> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
81 /// </remarks> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
82 public abstract int GenericParametersCount { get; } |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
83 |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
84 public virtual string ClrName { |
268 | 85 get { |
278
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
86 return GenericParametersCount != 0 ? $"{Name}`{GenericParametersCount}" : Name; |
268 | 87 } |
88 } | |
89 | |
278
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
90 /// <summary> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
91 /// Создает ссылку на специализацию текущего типа. |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
92 /// </summary> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
93 /// <param name="genericParameters">Ссылки на типы, которые будут использоваться для специализации текущего типа.</param> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
94 /// <returns>Специализация данного типа.</returns> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
95 public virtual SpecializedTypeReference MakeGenericType(TypeReference[] genericParameters) { |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
96 if (GenericParametersCount == 0) |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
97 throw new InvalidOperationException("Can't specialize a non-geneic type"); |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
98 |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
99 if (genericParameters == null || GenericParametersCount != genericParameters.Length) |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
100 throw new InvalidOperationException("Generic parameters count mismatch"); |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
101 |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
102 return new SpecializedTypeReference(this, genericParameters); |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
103 } |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
104 |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
105 /// <summary> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
106 /// Создает ссылку на тип массива указанной размерности, элементами которого являются экземпаляры даннго типа. |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
107 /// </summary> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
108 /// <param name="rank">Размерность, если размерность <c>1</c> создается вектор (<see cref="Type.MakeArrayType()"/>).</param> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
109 /// <returns>Ссылка на тип массива</returns> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
110 public ArrayTypeReference MakeArrayType(int rank) { |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
111 Safe.ArgumentInRange(rank > 0, nameof(rank)); |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
112 |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
113 return new ArrayTypeReference(this, rank); |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
114 } |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
115 |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
116 /// <summary> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
117 /// Создает ссылку на вложенный тип. |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
118 /// </summary> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
119 /// <param name="name">Имя типа</param> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
120 /// <param name="genericParameters">Количество параметров, если это общий тип, иначе 0.</param> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
121 /// <returns>Ссылка на вложенный тип.</returns> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
122 public TypeReference Create(string name, int genericParameters) { |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
123 Safe.ArgumentNotEmpty(name, nameof(name)); |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
124 Safe.ArgumentInRange(genericParameters >= 0, nameof(genericParameters)); |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
125 |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
126 return new NestedTypeReference(this, name, genericParameters); |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
127 } |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
128 |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
129 /// <summary> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
130 /// Возвращает строковое представление ссылки на тип. |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
131 /// </summary> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
132 /// <returns></returns> |
268 | 133 public override string ToString() { |
134 var builder = new StringBuilder(); | |
278
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
135 WriteTypeName(builder); |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
136 WriteTypeParams(builder); |
268 | 137 return builder.ToString(); |
138 } | |
278
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
139 |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
140 internal virtual void WriteTypeName(StringBuilder builder) { |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
141 if (!string.IsNullOrEmpty(Namespace)) |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
142 builder |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
143 .Append(Namespace) |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
144 .Append('.'); |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
145 builder.Append(Name); |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
146 } |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
147 |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
148 internal virtual void WriteTypeParams(StringBuilder builder) { |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
149 if (GenericParametersCount > 0) |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
150 builder |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
151 .Append('{') |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
152 .Append(',', GenericParametersCount-1) |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
153 .Append('}'); |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
154 } |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
155 |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
156 internal abstract void Visit(TypeResolutionContext visitor); |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
157 |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
158 /// <summary> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
159 /// Создает ссылку на тип. |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
160 /// </summary> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
161 /// <param name="ns">Пространство имен, либо его фрагмент.</param> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
162 /// <param name="name">Имя типа без указания на количество параметров, либо на то, что это массив.</param> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
163 /// <param name="genericParameters">Количество параметров типа, если это общий тип, иначе 0.</param> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
164 /// <returns>Ссылка на тип.</returns> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
165 public static TypeReference Create(string ns, string name, int genericParameters) { |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
166 Safe.ArgumentNotEmpty(name, nameof(name)); |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
167 Safe.ArgumentInRange(genericParameters >= 0, nameof(genericParameters)); |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
168 return new RootTypeReference(ns, name, genericParameters); |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
169 } |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
170 |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
171 /// <summary> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
172 /// Разирает строковую запись ссылки на тип. |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
173 /// </summary> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
174 /// <param name="typeSpec">Строковая запись ссылки на тип, например <c>Dictionary{String,String}</c></param> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
175 /// <returns>Ссылка на тип.</returns> |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
176 public static TypeReference Parse(string typeSpec) { |
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
177 var parser = new TypeReferenceParser(typeSpec); |
268 | 178 return parser.Parse(); |
179 } | |
278
6691aff01de1
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents:
268
diff
changeset
|
180 |
267 | 181 } |
182 } |