Allowed configuring properties with identical name

This commit is contained in:
radeanurazvan
2019-02-03 18:10:34 +02:00
parent f97c0d3ff3
commit d5ed13e823
5 changed files with 90 additions and 10 deletions

View File

@@ -0,0 +1,43 @@
using System;
namespace SieveUnitTests.ValueObjects
{
public sealed class Name : IEquatable<Name>
{
public Name(string value)
{
if (string.IsNullOrEmpty(value))
{
throw new InvalidOperationException("Invalid string!");
}
if (value.Length > 50)
{
throw new InvalidOperationException("String exceeds maximum name length!");
}
Value = value;
}
public string Value { get; private set; }
public bool Equals(Name other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return string.Equals(Value, other.Value);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj is Name && Equals((Name) obj);
}
public override int GetHashCode()
{
return (Value != null ? Value.GetHashCode() : 0);
}
}
}