title: Compare by values from unknown object types
body: <p>I want to do something like <a href="https://stackoverflow.com/questions/4332635/c-sharp-compare-two-objects-of-unknown-types-including-reference-and-value-type">this question</a>, but it isn't working as I'm expecting.</p>
  
  <p>I have a list of an object's properties and their types, an unknown object, and a list of default value types that I want to ignore from the object.</p>
  
  <pre><code>public void GetOnlyNonDefault(object oObject, IgnoreValues ignoreValues)
  {
      //properties is set beforehand
      for (int i = 0; i &lt; properties.Count; i++)
      {
          object originalValue = 
              oObject
                  .GetType()
                  .GetProperty(properties[i].Name)
                  .GetValue(oObject, null);
  
          //retrieving the default value I want to ignore for this property
          object ignoreValue = ignoreValues.GetDefaultOf(properties[i]);
  
          //Problem here
  
          //This doesn't work
          if (originalValue == ignoreValue) { continue; }
  
          //This works for nearly everything BUT enums
          if (ValueType.Equals(originalValue, ignoreValue)) { continue; }
      }
  }
  </code></pre>
  
  <p>I've read from <a href="https://stackoverflow.com/questions/529929/choosing-the-default-value-of-an-enum-type-without-having-to-change-values">here</a> that enums' default value is zero, and that's what I'm returning from <code>GetDefaultOf</code> when the type is an enum.
  How can I do a compare by values for all the value types including enums in the above code?</p>
  
  <p><strong>Edit:</strong> May be relevant, but the enums I'm using in the <code>oObject</code> class don't have any value set to 0, they all start at 1.</p>
  
  <pre><code>public enum UserStatus 
  {
      Regular = 1, Manager = 2, Director = 3, Admin = 4
  }
  </code></pre>
  
  <p><strong>Edit²:</strong> Here's a basic version of the code I'm trying to do giving the results I'm experiencing: <a href="http://pastebin.com/rfJA9CGp" rel="nofollow noreferrer">http://pastebin.com/rfJA9CGp</a></p>
  
  <p>I can't really change the enums because that's the point of this code, I don't know what is the object at runtime nor it's properties, but I want to figure any values different from the defined default (the class <code>IgnoreValues</code> contains the default values for all value types).</p>
  
  <p>I can't cast to <code>int</code> when it's an enum because then I'd ignore the case where an enum with <code>0</code> was actually defined in the code, so I'm looking for any way to compare the values.</p>