generated from ricardo/MVCLogin
67 lines
1.5 KiB
C#
67 lines
1.5 KiB
C#
using BaseDomain;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SumaTube.Domain.ValueObjects
|
|
{
|
|
public class Id : AValueObject
|
|
{
|
|
private string _value;
|
|
public string Value => _value;
|
|
|
|
public override bool GetValidationExpression()
|
|
{
|
|
return string.IsNullOrWhiteSpace(_value);
|
|
}
|
|
|
|
protected override IEnumerable<object> GetEqualityComponents()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Id(string valor, Guid id)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(valor))
|
|
throw new ArgumentException("O valor não pode ser nulo ou vazio", nameof(valor));
|
|
|
|
_value = valor;
|
|
}
|
|
|
|
public Id(Guid id)
|
|
{
|
|
_value = id.ToString("N");
|
|
}
|
|
|
|
|
|
private Id(string valor) : this(valor, Guid.NewGuid())
|
|
{
|
|
}
|
|
|
|
public static implicit operator Id(string valor)
|
|
{
|
|
return new Id(valor);
|
|
}
|
|
|
|
public static implicit operator Id(Guid id)
|
|
{
|
|
return new Id(id);
|
|
}
|
|
|
|
public static explicit operator string(Id vo)
|
|
{
|
|
return vo.Value.ToString();
|
|
}
|
|
|
|
public static explicit operator Guid(Id vo)
|
|
{
|
|
return Guid.Parse(vo.Value);
|
|
}
|
|
}
|
|
}
|