Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>MSDN has a good <a href="http://msdn.microsoft.com/en-us/library/aa288467(VS.71).aspx" rel="nofollow noreferrer">example</a> of how to do it:</p> <pre><code> public override bool Equals(object o) { try { return (bool) (this == (DBBool) o); } catch { return false; } } </code></pre> <p>Then you overload the == and !=:</p> <pre><code>// Equality operator. Returns dbNull if either operand is dbNull, // otherwise returns dbTrue or dbFalse: public static DBBool operator ==(DBBool x, DBBool y) { if (x.value == 0 || y.value == 0) return dbNull; return x.value == y.value? dbTrue: dbFalse; } // Inequality operator. Returns dbNull if either operand is // dbNull, otherwise returns dbTrue or dbFalse: public static DBBool operator !=(DBBool x, DBBool y) { if (x.value == 0 || y.value == 0) return dbNull; return x.value != y.value? dbTrue: dbFalse; } </code></pre> <p>And don't forget to overload the GetHash method.</p> <p>Edit:</p> <p>I wrote the following quick sample for using reflection in a compare. This would have to be much more comprehensive, I might try doing a blog on it if people want me to:</p> <pre><code>public class TestEquals { private int _x; public TestEquals(int x) { this._x = x; } public override bool Equals(object obj) { TestEquals te = (TestEquals)obj; if (te == null) return false; foreach (var field in typeof(TestEquals) .GetFields(BindingFlags.NonPublic | BindingFlags.Instance)) { if (!field.GetValue(this).Equals(field.GetValue(te))) return false; } return true; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload