Skip to content

Commit 7f1689d

Browse files
committed
рефакторинг конструкторов Структур; удален лишний using
1 parent cd31900 commit 7f1689d

File tree

2 files changed

+20
-35
lines changed

2 files changed

+20
-35
lines changed

src/OneScript.StandardLibrary/Collections/FixedStructureImpl.cs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ This Source Code Form is subject to the terms of the
66
----------------------------------------------------------*/
77

88
using System.Collections.Generic;
9-
using Newtonsoft.Json.Linq;
109
using OneScript.Contexts;
1110
using OneScript.Exceptions;
1211
using OneScript.Values;
@@ -169,21 +168,15 @@ private static FixedStructureImpl Constructor(StructureImpl structObject)
169168
[ScriptConstructor(Name = "По ключам и значениям")]
170169
public static FixedStructureImpl Constructor(IValue param1, IValue[] args)
171170
{
172-
var rawArgument = param1?.GetRawValue();
173-
if (rawArgument == null)
174-
return new FixedStructureImpl("");
175-
176-
if (rawArgument is BslStringValue s)
171+
return param1?.GetRawValue() switch
177172
{
178-
return new FixedStructureImpl((string)s, args);
179-
}
180-
else if (rawArgument is StructureImpl)
181-
{
182-
return new FixedStructureImpl(rawArgument as StructureImpl);
183-
}
173+
null => new FixedStructureImpl(""),
174+
BslStringValue s => new FixedStructureImpl((string)s, args),
175+
StructureImpl structure => new FixedStructureImpl(structure),
176+
177+
_ => throw new RuntimeException("В качестве параметра для конструктора можно передавать только Структура или Ключи и Значения")
178+
};
179+
}
184180

185-
throw new RuntimeException("В качестве параметра для конструктора можно передавать только Структура или Ключи и Значения");
186181
}
187-
188-
}
189182
}

src/OneScript.StandardLibrary/Collections/StructureImpl.cs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ This Source Code Form is subject to the terms of the
55
at http://mozilla.org/MPL/2.0/.
66
----------------------------------------------------------*/
77

8-
using System;
98
using System.Collections.Generic;
109
using OneScript.Commons;
1110
using OneScript.Contexts;
@@ -29,11 +28,10 @@ public StructureImpl()
2928

3029
public StructureImpl(string strProperties, params IValue[] values)
3130
{
32-
var props = strProperties.Split(',');
33-
34-
for (int i = 0, nprop = 0; i < props.Length; i++)
31+
var nprop = 0;
32+
foreach (var item in strProperties.Split(','))
3533
{
36-
var prop = props[i].Trim();
34+
var prop = item.Trim();
3735
if (prop.Equals(string.Empty))
3836
continue;
3937

@@ -49,7 +47,7 @@ public StructureImpl(FixedStructureImpl structure)
4947
Insert(keyValue.Key.AsString(), keyValue.Value);
5048
}
5149
}
52-
50+
5351
[ContextMethod("Вставить")]
5452
public void Insert(string name, IValue val = null)
5553
{
@@ -66,7 +64,7 @@ public void Insert(string name, IValue val = null)
6664
{
6765
val = ValueFactory.Create();
6866
}
69-
67+
7068
SetPropValue(num, val);
7169
}
7270

@@ -255,20 +253,14 @@ private static StructureImpl Constructor(FixedStructureImpl fixedStruct)
255253
[ScriptConstructor(Name = "По ключам и значениям")]
256254
public static StructureImpl Constructor(IValue param1, IValue[] args)
257255
{
258-
var rawArgument = param1?.GetRawValue();
259-
if (rawArgument == null)
260-
return new StructureImpl();
261-
262-
if (rawArgument is BslStringValue s)
256+
return param1?.GetRawValue() switch
263257
{
264-
return new StructureImpl((string)s, args);
265-
}
266-
else if (rawArgument is FixedStructureImpl)
267-
{
268-
return new StructureImpl(rawArgument as FixedStructureImpl);
269-
}
270-
271-
throw new RuntimeException("В качестве параметра для конструктора можно передавать только ФиксированнаяСтруктура или Ключи и Значения");
258+
null => new StructureImpl(),
259+
BslStringValue s => new StructureImpl((string)s, args),
260+
FixedStructureImpl fixedstr => new StructureImpl(fixedstr),
261+
262+
_ => throw new RuntimeException("В качестве параметра для конструктора можно передавать только ФиксированнаяСтруктура или Ключи и Значения")
263+
};
272264
}
273265

274266

0 commit comments

Comments
 (0)