Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Collection<T> : IDisposable
- {
- internal T[] Item = { };
- /// <summary>
- /// Quantidade de Items na Coleção
- /// </summary>
- internal int Length { get; private set; }
- [System.Runtime.CompilerServices.IndexerName("HelperItem")]
- internal T this[int Index]
- {
- get => Item[Index];
- set => Item[Index] = value;
- }
- /// <summary>
- /// Copia outra coleção
- /// </summary>
- /// <param name="value"></param>
- public void Copy(Collection<T> value)
- {
- Clear();
- if (value.Length > 0)
- {
- Item = new T[value.Length];
- for (int i = 0; i < Item.Length; i++)
- Item[i] = value[i];
- Length = value.Length;
- }
- }
- /// <summary>
- /// Limpa a coleção
- /// </summary>
- internal void Clear()
- {
- Item = new T[]{ };
- Length = 0;
- }
- /// <summary>
- /// Adiciona um item na coleção
- /// </summary>
- /// <param name="value"></param>
- internal void Add(T value)
- {
- Array.Resize(ref Item, Length + 1);
- Item[Length] = value;
- Length++;
- }
- /// <summary>
- /// Remove um item da coleção pelo seu ID
- /// </summary>
- /// <param name="at"></param>
- internal void RemoveAt(int at)
- {
- if (Length == 0)
- return;
- if (at < 0 || at >= Length)
- return;
- // Re-Organiza a coleção
- if (at < Length - 1)
- {
- for (int i = 0; i < Length - 2; i++)
- {
- Item[i] = Item[i + 1];
- }
- }
- Array.Resize(ref Item, Length - 1);
- Length--;
- }
- /// <summary>
- /// Remove um item da coleção
- /// </summary>
- /// <param name="value"></param>
- internal void Remove(T value)
- {
- if (Length == 0)
- return;
- int ID = IndexOf(value);
- RemoveAt(ID);
- }
- /// <summary>
- /// Identifica a ID na coleção de um determinado Item
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- public int IndexOf(T value) => Array.IndexOf(Item, value);
- ~Collection() => Dispose();
- public void Dispose() => GC.SuppressFinalize(this);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement