Skip to content

Commit 02c147d

Browse files
committed
добавлено свойство ДоступныеЗначения
1 parent c150b55 commit 02c147d

1 file changed

Lines changed: 45 additions & 3 deletions

File tree

src/OneScript.StandardLibrary/Collections/ValueList/ValueListImpl.cs

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,48 @@ public override void SetIndexedValue(IValue index, IValue val)
5959
/// </summary>
6060
/// <value>ОписаниеТипов</value>
6161
[ContextProperty("ТипЗначения", "ValueType")]
62-
public TypeDescription ListValueType { get; set; } = new();
62+
public TypeDescription ListValueType { get; set; } = new();
63+
64+
65+
ValueListImpl _availableValues;
66+
67+
/// <summary>
68+
/// Ограничивает допустимые значения для элементов данного списка значений.
69+
/// Возможные значения: Неопределено - ограничения отсутствуют,
70+
/// СписокЗначений - список допустимых значений
71+
/// </summary>
72+
/// <remarks>
73+
/// Проверка допустимости добавляемых значений производится после приведения к указанным в ТипЗначения (если есть)
74+
/// </remarks>
75+
/// <value>СписокЗначений или Неопределено</value>
76+
[ContextProperty("ДоступныеЗначения", "AvailableValues")]
77+
public IValue AvailableValues
78+
{
79+
get
80+
{
81+
if (_availableValues != null)
82+
return _availableValues;
83+
84+
return BslUndefinedValue.Instance;
85+
}
6386

87+
set
88+
{
89+
switch (value)
90+
{
91+
case BslUndefinedValue:
92+
_availableValues = null;
93+
break;
94+
95+
case ValueListImpl vl:
96+
_availableValues = vl;
97+
break;
98+
99+
default: throw RuntimeException.InvalidArgumentType();
100+
}
101+
}
102+
}
103+
64104
/// <summary>
65105
/// Получить элемент по индексу
66106
/// </summary>
@@ -116,11 +156,13 @@ public ValueListItem Insert(int index, IValue value = null, string presentation
116156

117157
private ValueListItem CreateNewListItem(IValue value, string presentation, bool check, IValue picture)
118158
{
119-
var adjValue = ListValueType.AdjustValue(value);
159+
var newValue = ListValueType.AdjustValue(value);
160+
if (_availableValues is not null)
161+
newValue = _availableValues.FindByValue(newValue);
120162

121163
return new ValueListItem
122164
{
123-
Value = adjValue,
165+
Value = newValue,
124166
Presentation = presentation,
125167
Check = check,
126168
Picture = picture

0 commit comments

Comments
 (0)