/
EvilBeaver
/
OneScript
Обзор
Документация
Войти
/
EvilBeaver
/
OneScript
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
v2.0.0
src/ScriptEngine/Machine/JoinedScopes.cs
60 строк
2 KB
EvilBeaver
Заменен подход к получению переменных из контекстов, класс IAttachableContext.cs теперь используется для получения переменных по номеру, а не массивом.
25 ноя 2025, 12:04
25 ноя 2025, 12:04
cb25ba5
Код
Авторство
О чём код?
/*---------------------------------------------------------- This Source Code Form is subject to the terms of the Mozilla Public License, v.2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. ----------------------------------------------------------*/ using System; using System.Collections; using System.Collections.Generic; using OneScript.Contexts; namespace ScriptEngine.Machine { /// <summary> /// Оборачивающий контейнер. Хранит внешние области видимости и одну локальную, как единый плоский список. /// </summary> public class JoinedScopes : IReadOnlyList<IAttachableContext> { private readonly IReadOnlyList<IAttachableContext> _outerScopes; private readonly IAttachableContext _innerScope; public JoinedScopes(IReadOnlyList<IAttachableContext> outerScopes, IAttachableContext innerScope) { _outerScopes = outerScopes ?? throw new ArgumentNullException(nameof(outerScopes)); _innerScope = innerScope ?? throw new ArgumentNullException(nameof(innerScope)); } public IEnumerator<IAttachableContext> GetEnumerator() { foreach (var scope in _outerScopes) { yield return scope; } yield return _innerScope; } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } public int Count => _outerScopes.Count + 1; public IAttachableContext this[int index] { get { if (index < 0 || index >= Count) throw new IndexOutOfRangeException(); if (index == _outerScopes.Count) return _innerScope; return _outerScopes[index]; } } } }