Instead of x == null
you can use (object)x == null
or Object.ReferenceEquals(x, null)
:
public static bool operator ==(Tags x, Tags y) { if ((object)x == null && (object)y == null) return true; if ((object)x == null || (object)y == null) return false; return x.mask == y.mask; }
But you must also implement Equals
and GetHashCode
:
public override bool Equals(object obj) { return this.Equals(obj as Tags); } public bool Equals(Tags tags) { return (object)tags != null && this.mask == tags.mask; } public override int GetHashCode() { return this.mask.GetHashCode(); }
Now operator ==
can simply be written:
public static bool operator ==(Tags x, Tags y) { return (object)x != null ? x.Equals(y) : (object)y == null; }
source share