mirror of
https://github.com/modernuo/ModernUO
synced 2026-08-11 22:23:06 -04:00
- [X] Fixes some issues with the type caching - [X] Changes type check default to ignore case - [X] Splits out type caching of insensitive and sensitive lists. This means less stuff to iterate through when checking a type against the string. - [X] Adds an ArrayEnumerator, mostly for reference purposes (copy/paste as needed)
79 lines
2.5 KiB
C#
79 lines
2.5 KiB
C#
/*************************************************************************
|
|
* ModernUO *
|
|
* Copyright (C) 2019-2021 - ModernUO Development Team *
|
|
* Email: hi@modernuo.com *
|
|
* File: ArrayEnumerator.cs *
|
|
* *
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
* it under the terms of the GNU General Public License as published by *
|
|
* the Free Software Foundation, either version 3 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
* You should have received a copy of the GNU General Public License *
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
*************************************************************************/
|
|
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Server.Collections
|
|
{
|
|
/// <summary>
|
|
/// Non-thread safe, non-guarded enumerator for classes that have internal arrays.
|
|
/// Recommended to copy this and use it as a nested struct.
|
|
/// Recommend adding version checking to properly guard against modification during enumeration.
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
public struct ArrayEnumerator<T> : IEnumerator<T>
|
|
{
|
|
private readonly T[] _array;
|
|
private int _index;
|
|
private T? _current;
|
|
|
|
public ArrayEnumerator(T[] array)
|
|
{
|
|
_array = array;
|
|
_index = 0;
|
|
_current = default;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
|
|
public bool MoveNext()
|
|
{
|
|
T[] localList = _array;
|
|
|
|
if ((uint)_index < (uint)localList.Length)
|
|
{
|
|
_current = _array[_index++];
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public T? Current => _current!;
|
|
|
|
object IEnumerator.Current
|
|
{
|
|
get
|
|
{
|
|
if (_index == 0 || _index == _array.Length + 1)
|
|
{
|
|
throw new InvalidOperationException(nameof(_index));
|
|
}
|
|
|
|
return _current;
|
|
}
|
|
}
|
|
|
|
void IEnumerator.Reset()
|
|
{
|
|
_index = 0;
|
|
_current = default;
|
|
}
|
|
}
|
|
}
|