kreta/Kreta.WebApi/Ellenorzo/Kreta.Ellenorzo.Domain/VN/Logic/UidLogic.cs
2024-03-13 00:33:46 +01:00

43 lines
1.4 KiB
C#

using System;
using Kreta.Ellenorzo.Domain.VN.Interfaces;
namespace Kreta.Ellenorzo.Domain.VN.Logic
{
/// <summary>
/// Author: Kovács Kornél (DevKornél) Created On: 2019.07.
/// </summary>
public static class UidLogic
{
public static T GetUid<T>(string uidRaw, Converter<string[], T> uidConverter) where T : class, IReadonlyUidRaw
{
if (string.IsNullOrWhiteSpace(uidRaw))
{
return null;
}
string[] compositeKey = uidRaw.Split(Constant.UidInnerDelimiter);
T uid = uidConverter.Invoke(compositeKey);
return uid;
}
public static string[] GetCompositeKeyElements(string uidRaw) => string.IsNullOrWhiteSpace(uidRaw) ? null : uidRaw.Split(Constant.UidInnerDelimiter);
public static string Concat(params object[] compositeKeyElements)
{
for (int i = 0; i < compositeKeyElements.Length; i++)
{
if (compositeKeyElements[i] == null)
{
compositeKeyElements[i] = Constant.UidNullValue;
}
else if (string.IsNullOrWhiteSpace(compositeKeyElements[i].ToString()))
{
compositeKeyElements[i] = Constant.UidNanValue;
}
}
return string.Join(Constant.UidInnerDelimiter.ToString(), compositeKeyElements);
}
}
}