kreta/Kreta.WebApi/Naplo/Kreta.Naplo.Domain/V3/Indexers/UidsCollection.cs
2024-03-13 00:33:46 +01:00

50 lines
1.4 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using Kreta.Core.Enum;
using Kreta.Core.Exceptions;
using Kreta.Naplo.Domain.V3.Interfaces;
namespace Kreta.Naplo.Domain.V3.Indexers
{
public class UidsCollection<T> : IEnumerable<T> where T : class, IReadonlyUidRaw
{
private readonly List<T> _uids = new List<T>();
public UidsCollection(string uidsRaw, Converter<string[], T> uidsConverter)
{
if (string.IsNullOrWhiteSpace(uidsRaw))
{
return;
}
string[] uidArray = uidsRaw.Split(Constant.UidDelimiter);
if (uidArray.Length > 50)
{
throw new BlException(BlExceptionType.ListaTobbMint50ElemetTartalmaz);
}
_uids = new List<T>(uidArray.Length);
for (int i = 0; i < uidArray.Length; i++)
{
_uids.Add(GetUid(uidArray[i]));
}
T GetUid(string uidRaw)
{
string[] compositeKey = uidRaw.Split(Constant.UidInnerDelimiter);
T uid = uidsConverter.Invoke(compositeKey);
return uid;
}
}
public T this[int index] => _uids[index];
public IEnumerator GetEnumerator() => throw new NotImplementedException();
IEnumerator<T> IEnumerable<T>.GetEnumerator() => _uids.GetEnumerator();
}
}