sumatube/SumaTube.Domain/ValueObjects/Name.cs
2025-04-20 23:33:46 -03:00

52 lines
1.3 KiB
C#

using BaseDomain;
namespace SumaTube.Domain
{
public class Name : AValueObject
{
public Name(string fullName)
{
this.FullName = fullName;
var names = fullName.Split(' ');
if (names.Length >= 2)
{
this.FirstName = names[0];
this.LastName = names[names.Length - 1];
}
}
public Name(string firstName, string lastName)
{
this.FirstName = firstName;
this.LastName = lastName;
}
public string FullName { get; private set; }
public string FirstName { get; private set; }
public string LastName { get; private set; }
public override bool GetValidationExpression()
{
return this.IsValid = this.IsValidName(FullName);
}
public override string ToString()
{
return this.FullName;
}
protected override IEnumerable<object> GetEqualityComponents()
{
yield return this.FullName;
}
private bool IsValidName(string fullName)
{
return fullName.Contains(' ');
}
public static implicit operator string(Name name) => name.FullName;
public static explicit operator Name(string fullname) => new Name(fullname);
}
}