Created
March 24, 2016 07:30
-
-
Save abenedykt/d4aa47f3e883aebdb16c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class StringValueObject<T> where T : StringValueObject<T> | |
{ | |
public string Value { get; protected set; } | |
public static bool operator ==(StringValueObject<T> a, StringValueObject<T> b) | |
{ | |
if (ReferenceEquals(a, b)) | |
{ | |
return true; | |
} | |
if (((object)a == null) || ((object)b == null)) | |
{ | |
return false; | |
} | |
return a.Equals(b); | |
} | |
public static bool operator !=(StringValueObject<T> a, StringValueObject<T> b) | |
{ | |
return !(a == b); | |
} | |
protected bool Equals(StringValueObject<T> other) | |
{ | |
return Value.Equals(other.Value); | |
} | |
public override bool Equals(object obj) | |
{ | |
if (ReferenceEquals(null, obj)) return false; | |
if (ReferenceEquals(this, obj)) return true; | |
return obj.GetType() == GetType() && Equals((StringValueObject<T>)obj); | |
} | |
public override int GetHashCode() | |
{ | |
return Value.GetHashCode(); | |
} | |
public static T From(string value) | |
{ | |
var obj = (StringValueObject<T>)Activator.CreateInstance(typeof (T), true); | |
obj.Value = value; | |
return obj as T; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment