init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
|
@ -0,0 +1,58 @@
|
|||
using System;
|
||||
using Kreta.Core.Validation.Exceptions;
|
||||
using Kreta.Core.Validation.Exceptions.Enum;
|
||||
using Kreta.Resources;
|
||||
|
||||
namespace Kreta.BusinessLogic.Classes.MobileApi.Naplo.V3.Co.Enum
|
||||
{
|
||||
public class NaploEnumCo<T> where T : struct, IConvertible
|
||||
{
|
||||
public static implicit operator NaploEnumCo<T>(int id) => new NaploEnumCo<T>(id);
|
||||
public static implicit operator NaploEnumCo<T>(T enumValue) => new NaploEnumCo<T>(Convert.ToInt32(enumValue));
|
||||
public static bool operator ==(NaploEnumCo<T> lhsWrapperCo, T rhsEnum) => lhsWrapperCo.GetEnum().Equals(rhsEnum);
|
||||
public static bool operator !=(NaploEnumCo<T> lhsWrapperCo, T rhsEnum) => !lhsWrapperCo.GetEnum().Equals(rhsEnum);
|
||||
|
||||
public string EnumTypeNameWPostFix => typeof(T).Name;
|
||||
public string EnumTypeName => EnumTypeNameWPostFix.Replace("Enum", "").Replace("enum", "");
|
||||
public bool IsGeneratedEnum => !string.IsNullOrWhiteSpace(Nev);
|
||||
|
||||
public T GetEnum()
|
||||
{
|
||||
T enumValue;
|
||||
|
||||
if (!System.Enum.TryParse<T>(Nev, out enumValue))
|
||||
{
|
||||
throw new ValidationException(ValidationErrorType.ResourceNotFound, ErrorResource.NemEngedelyezettVagyNemLetezoEnum);
|
||||
}
|
||||
|
||||
return enumValue;
|
||||
}
|
||||
public int Id { get; private set; }
|
||||
public string Nev { get; private set; }
|
||||
|
||||
public NaploEnumCo(int id)
|
||||
{
|
||||
Fill(id);
|
||||
if (!typeof(T).IsEnum)
|
||||
{
|
||||
throw new ArgumentException("T must be an enum");
|
||||
}
|
||||
}
|
||||
|
||||
private void Fill(int id)
|
||||
{
|
||||
Id = id;
|
||||
Nev = System.Enum.GetName(typeof(T), id);
|
||||
if (!typeof(T).IsEnum)
|
||||
{
|
||||
throw new ArgumentException("T must be an enum");
|
||||
}
|
||||
}
|
||||
|
||||
public NaploEnumCo(int id, string nev)
|
||||
{
|
||||
Id = id;
|
||||
Nev = nev;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue