Created
February 7, 2020 15:07
-
-
Save louthy/8f9731fd60ff0c52015b005815b03f9e 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
[System.Serializable] | |
public partial struct Person : System.IEquatable<Person>, System.IComparable<Person>, System.IComparable | |
{ | |
public Person(string Forename, string Surname) | |
{ | |
this.Forename = Forename; | |
this.Surname = Surname; | |
} | |
public static Person New(string Forename, string Surname) => new Person(Forename, Surname); | |
public void Deconstruct(out string Forename, out string Surname) | |
{ | |
Forename = this.Forename; | |
Surname = this.Surname; | |
} | |
private Person(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) | |
{ | |
this.Forename = (string)info.GetValue("Forename", typeof(string)); | |
this.Surname = (string)info.GetValue("Surname", typeof(string)); | |
} | |
public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) | |
{ | |
info.AddValue("Forename", this.Forename); | |
info.AddValue("Surname", this.Surname); | |
} | |
public static bool operator ==(Person x, Person y) => x.Equals(y); | |
public static bool operator !=(Person x, Person y) => !(x == y); | |
public static bool operator>(Person x, Person y) => x.CompareTo(y) > 0; | |
public static bool operator <(Person x, Person y) => x.CompareTo(y) < 0; | |
public static bool operator >=(Person x, Person y) => x.CompareTo(y) >= 0; | |
public static bool operator <=(Person x, Person y) => x.CompareTo(y) <= 0; | |
public bool Equals(Person other) | |
{ | |
if (LanguageExt.Prelude.isnull(other)) | |
return false; | |
if (!default(LanguageExt.ClassInstances.EqDefault<string>).Equals(this.Forename, other.Forename)) | |
return false; | |
if (!default(LanguageExt.ClassInstances.EqDefault<string>).Equals(this.Surname, other.Surname)) | |
return false; | |
return true; | |
} | |
public override bool Equals(object obj) => obj is Person tobj && Equals(tobj); | |
public int CompareTo(object obj) => obj is Person p ? CompareTo(p) : 1; | |
public int CompareTo(Person other) | |
{ | |
if (LanguageExt.Prelude.isnull(other)) | |
return 1; | |
int cmp = 0; | |
cmp = default(LanguageExt.ClassInstances.OrdDefault<string>).Compare(this.Forename, other.Forename); | |
if (cmp != 0) | |
return cmp; | |
cmp = default(LanguageExt.ClassInstances.OrdDefault<string>).Compare(this.Surname, other.Surname); | |
if (cmp != 0) | |
return cmp; | |
return 0; | |
} | |
public override int GetHashCode() | |
{ | |
const int fnvOffsetBasis = -2128831035; | |
const int fnvPrime = 16777619; | |
int state = fnvOffsetBasis; | |
unchecked | |
{ | |
state = (default(LanguageExt.ClassInstances.EqDefault<string>).GetHashCode(this.Forename) ^ state) * fnvPrime; | |
state = (default(LanguageExt.ClassInstances.EqDefault<string>).GetHashCode(this.Surname) ^ state) * fnvPrime; | |
} | |
return state; | |
} | |
public override string ToString() | |
{ | |
var sb = new System.Text.StringBuilder(); | |
sb.Append("Person("); | |
sb.Append(LanguageExt.Prelude.isnull(Forename) ? $"Forename: [null]" : $"Forename: {Forename}"); | |
sb.Append($", "); | |
sb.Append(LanguageExt.Prelude.isnull(Surname) ? $"Surname: [null]" : $"Surname: {Surname}"); | |
sb.Append(")"); | |
return sb.ToString(); | |
} | |
public Person With(string Forename = null, string Surname = null) => new Person(Forename ?? this.Forename, Surname ?? this.Surname); | |
public static Lens<Person, string> forename => __LensFields.forename; | |
public static Lens<Person, string> surname => __LensFields.surname; | |
static class __LensFields | |
{ | |
public static readonly Lens<Person, string> forename = Lens<Person, string>.New(_x => _x.Forename, _x => _y => _y.With(Forename: _x)); | |
public static readonly Lens<Person, string> surname = Lens<Person, string>.New(_x => _x.Surname, _x => _y => _y.With(Surname: _x)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment