Skip to content

Commit

Permalink
fix #1452 значение по умолчанию при добавлении в СписокЗначений
Browse files Browse the repository at this point in the history
  • Loading branch information
EvilBeaver committed Oct 7, 2024
1 parent 133c26b commit 4dd806e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/ScriptEngine.HostedScript/Library/ValueList/ValueListImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ This Source Code Form is subject to the terms of the
was not distributed with this file, You can obtain one
at http://mozilla.org/MPL/2.0/.
----------------------------------------------------------*/

using System;
using ScriptEngine.Machine;
using ScriptEngine.Machine.Contexts;
using System.Collections.Generic;
using System.Linq;
using ScriptEngine.Machine.Values;

namespace ScriptEngine.HostedScript.Library.ValueList
{
Expand Down Expand Up @@ -76,7 +79,7 @@ public ValueListItem GetValue(IValue index)
/// <param name="picture">Картинка (необязательный) - Визуальное представление добавляемого значения</param>
/// <returns>ЭлементСпискаЗначений</returns>
[ContextMethod("Добавить", "Add")]
public ValueListItem Add(IValue value, string presentation = null, bool check = false, IValue picture = null)
public ValueListItem Add(IValue value = null, string presentation = null, bool check = false, IValue picture = null)
{
var newItem = CreateNewListItem(value, presentation, check, picture);

Expand All @@ -94,7 +97,7 @@ public ValueListItem Add(IValue value, string presentation = null, bool check =
/// <param name="picture">Картинка (необязательный) - Визуальное представление добавляемого значения</param>
/// <returns>ЭлементСпискаЗначений</returns>
[ContextMethod("Вставить", "Insert")]
public ValueListItem Insert(int index, IValue value, string presentation = null, bool check = false, IValue picture = null)
public ValueListItem Insert(int index, IValue value = null, string presentation = null, bool check = false, IValue picture = null)
{
var newItem = CreateNewListItem(value, presentation, check, picture);
_items.Insert(index, newItem);
Expand All @@ -105,7 +108,7 @@ public ValueListItem Insert(int index, IValue value, string presentation = null,
private static ValueListItem CreateNewListItem(IValue value, string presentation, bool check, IValue picture)
{
var newItem = new ValueListItem();
newItem.Value = value;
newItem.Value = value ?? UndefinedValue.Instance;
newItem.Presentation = presentation;
newItem.Check = check;
newItem.Picture = picture;
Expand Down Expand Up @@ -285,7 +288,7 @@ private int SafeCompare(IValue x, IValue y)
catch(RuntimeException)
{
// Сравнение типов не поддерживается
return x.AsString().CompareTo(y.AsString());
return string.Compare(x?.AsString(), y?.AsString(), StringComparison.Ordinal);
}
}

Expand Down

0 comments on commit 4dd806e

Please sign in to comment.