Skip to content

Commit cab4327

Browse files
committed
Порядок и количество квалификаторов в конструкторе ОписанияТипов - сделано совместимо
1 parent 88c7a1a commit cab4327

File tree

1 file changed

+80
-27
lines changed

1 file changed

+80
-27
lines changed

src/ScriptEngine.HostedScript/Library/TypeDescription/TypeDescription.cs

Lines changed: 80 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public TypeDescription(IEnumerable<TypeTypeValue> types = null,
2727
{
2828
_types.AddRange(types);
2929
}
30+
3031
NumberQualifiers = numberQualifiers ?? new NumberQualifiers();
3132
StringQualifiers = stringQualifiers ?? new StringQualifiers();
3233
DateQualifiers = dateQualifiers ?? new DateQualifiers();
@@ -186,71 +187,122 @@ public static TypeDescription BooleanType()
186187
return new TypeDescription(new TypeTypeValue[] { TypeBoolean() });
187188
}
188189

190+
191+
private class TypeQualifiersSet
192+
{
193+
public readonly NumberQualifiers numberQualifiers = null;
194+
public readonly StringQualifiers stringQualifiers = null;
195+
public readonly DateQualifiers dateQualifiers = null;
196+
public readonly BinaryDataQualifiers binaryDataQualifiers = null;
197+
198+
public TypeQualifiersSet(IValue p2, IValue p3, IValue p4, IValue p5, IValue p6, IValue p7)
199+
{
200+
int nParam = 1;
201+
foreach (var qual in new[] { p2, p3, p4, p5, p6, p7 })
202+
{
203+
nParam++;
204+
205+
if (qual == null)
206+
continue;
207+
208+
var rawQual = qual.GetRawValue();
209+
210+
if (rawQual is NumberQualifiers)
211+
{
212+
numberQualifiers = (NumberQualifiers)rawQual;
213+
}
214+
else if (rawQual is StringQualifiers)
215+
{
216+
stringQualifiers = (StringQualifiers)rawQual;
217+
}
218+
else if (rawQual is DateQualifiers)
219+
{
220+
dateQualifiers = (DateQualifiers)rawQual;
221+
}
222+
else if (rawQual is BinaryDataQualifiers)
223+
{
224+
binaryDataQualifiers = (BinaryDataQualifiers)rawQual;
225+
}
226+
else
227+
{
228+
throw RuntimeException.InvalidNthArgumentType(nParam);
229+
}
230+
}
231+
}
232+
}
233+
189234
[ScriptConstructor]
190235
public static TypeDescription Constructor(
191236
IValue source = null,
192-
IValue p1 = null,
193237
IValue p2 = null,
194238
IValue p3 = null,
195239
IValue p4 = null,
196240
IValue p5 = null,
197-
IValue p6 = null)
241+
IValue p6 = null,
242+
IValue p7 = null)
198243
{
199244
var rawSource = source?.GetRawValue();
200245

201246
if (rawSource == null || rawSource.DataType == DataType.Undefined)
202247
{
203-
// первый параметр имеет право быть не задан только в таком конструкторе
204-
return ConstructByOtherDescription(null, p1, p2, p3, p4, p5, p6);
248+
// пустой первый параметр - нет объекта-основания
249+
// добавляемые/вычитаемые типы не допускаются, квалификаторы игнорируются
250+
251+
// только для контроля типов
252+
var _ = new TypeQualifiersSet(p2, p3, p4, p5, p6, p7);
253+
254+
return new TypeDescription();
205255
}
206256

207257
if (rawSource is TypeDescription)
208258
{
209-
return ConstructByOtherDescription(rawSource, p1, p2, p3, p4, p5, p6);
259+
return ConstructByOtherDescription(rawSource, p2, p3, p4, p5, p6, p7);
210260
}
211261

212262
if (rawSource.DataType == DataType.String || rawSource is ArrayImpl)
213263
{
214-
// TODO: проверить, что p5 и p6 не заданы
215-
return ConstructByQualifiers(rawSource, p1, p2, p3, p4);
264+
return ConstructByQualifiers(rawSource, p2, p3, p4, p5, p6, p7);
216265
}
217266

218267
throw RuntimeException.InvalidArgumentValue();
219268
}
220269

221270
public static TypeDescription ConstructByQualifiers(
222271
IValue types,
223-
IValue numberQualifiers = null,
224-
IValue stringQualifiers = null,
225-
IValue dateQualifiers = null,
226-
IValue binaryDataQualifiers = null)
272+
IValue p2 = null,
273+
IValue p3 = null,
274+
IValue p4 = null,
275+
IValue p5 = null,
276+
IValue p6 = null,
277+
IValue p7 = null)
227278
{
228279
var _types = ConstructTypeList(types);
229280
if (_types == null)
230-
throw RuntimeException.InvalidArgumentType(nameof(types));
281+
throw RuntimeException.InvalidNthArgumentType(2);
231282

232-
var paramNumberQ = numberQualifiers?.GetRawValue() as NumberQualifiers;
233-
var paramStringQ = stringQualifiers?.GetRawValue() as StringQualifiers;
234-
var paramDateQ = dateQualifiers?.GetRawValue() as DateQualifiers;
235-
var paramBinaryDataQ = binaryDataQualifiers?.GetRawValue() as BinaryDataQualifiers;
283+
var qualSet = new TypeQualifiersSet(p2,p3,p4,p5,p6,p7);
236284

237-
return new TypeDescription(_types, paramNumberQ, paramStringQ, paramDateQ, paramBinaryDataQ);
285+
return new TypeDescription(_types,
286+
qualSet.numberQualifiers,
287+
qualSet.stringQualifiers,
288+
qualSet.dateQualifiers,
289+
qualSet.binaryDataQualifiers);
238290
}
239291

240292
public static TypeDescription ConstructByOtherDescription(
241293
IValue typeDescription = null,
242294
IValue addTypes = null,
243295
IValue removeTypes = null,
244-
IValue numberQualifiers = null,
245-
IValue stringQualifiers = null,
246-
IValue dateQualifiers = null,
247-
IValue binaryDataQualifiers = null)
296+
IValue p4 = null,
297+
IValue p5 = null,
298+
IValue p6 = null,
299+
IValue p7 = null)
248300
{
249301
var td = typeDescription as TypeDescription;
250302

251303
var removeTypesList = ConstructTypeList(removeTypes);
252304
if (removeTypesList == null)
253-
throw RuntimeException.InvalidArgumentType(nameof(removeTypes));
305+
throw RuntimeException.InvalidNthArgumentType(3);
254306

255307

256308
var _types = new List<TypeTypeValue>();
@@ -271,12 +323,13 @@ public static TypeDescription ConstructByOtherDescription(
271323
throw RuntimeException.InvalidArgumentType(nameof(addTypes));
272324
_types.AddRange(addTypesList);
273325

274-
var paramNumberQ = numberQualifiers?.AsObject() as NumberQualifiers ?? td?.NumberQualifiers;
275-
var paramStringQ = stringQualifiers?.AsObject() as StringQualifiers ?? td?.StringQualifiers;
276-
var paramDateQ = dateQualifiers?.AsObject() as DateQualifiers ?? td?.DateQualifiers;
277-
var paramBinaryDataQ = binaryDataQualifiers?.AsObject() as BinaryDataQualifiers ?? td?.BinaryDataQualifiers;
326+
var qualSet = new TypeQualifiersSet(null, null, p4, p5, p6, p7);
278327

279-
return new TypeDescription(_types, paramNumberQ, paramStringQ, paramDateQ, paramBinaryDataQ);
328+
return new TypeDescription(_types,
329+
qualSet.numberQualifiers,
330+
qualSet.stringQualifiers,
331+
qualSet.dateQualifiers,
332+
qualSet.binaryDataQualifiers);
280333
}
281334
}
282335
}

0 commit comments

Comments
 (0)