/
TON618OFF
/
Unity-Project-RTU
Обзор
Документация
Войти
/
TON618OFF
/
Unity-Project-RTU
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Library/PackageCache/com.unity.visualscripting@1.9.4/Runtime/VisualScripting.Core/Collections/VariantCollection.cs
99 строк
2 KB
TON618OFF
release
03 окт 2024, 22:20
03 окт 2024, 22:20
7c70e9f
Код
Авторство
О чём код?
using System; using System.Collections; using System.Collections.Generic; namespace Unity.VisualScripting { public class VariantCollection<TBase, TImplementation> : ICollection<TBase> where TImplementation : TBase { public VariantCollection(ICollection<TImplementation> implementation) { if (implementation == null) { throw new ArgumentNullException(nameof(implementation)); } this.implementation = implementation; } public ICollection<TImplementation> implementation { get; private set; } public int Count => implementation.Count; public bool IsReadOnly => implementation.IsReadOnly; IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } public IEnumerator<TBase> GetEnumerator() { foreach (var i in implementation) { yield return i; } } public void Add(TBase item) { if (!(item is TImplementation)) { throw new NotSupportedException(); } implementation.Add((TImplementation)item); } public void Clear() { implementation.Clear(); } public bool Contains(TBase item) { if (!(item is TImplementation)) { throw new NotSupportedException(); } return implementation.Contains((TImplementation)item); } public bool Remove(TBase item) { if (!(item is TImplementation)) { throw new NotSupportedException(); } return implementation.Remove((TImplementation)item); } public void CopyTo(TBase[] array, int arrayIndex) { if (array == null) { throw new ArgumentNullException(nameof(array)); } if (arrayIndex < 0) { throw new ArgumentOutOfRangeException(nameof(arrayIndex)); } if (array.Length - arrayIndex < Count) { throw new ArgumentException(); } var implementationArray = new TImplementation[Count]; implementation.CopyTo(implementationArray, 0); for (var i = 0; i < Count; i++) { array[i + arrayIndex] = implementationArray[i]; } } } }