title: Compare Equality of two C# Class instances (generated from XML)
body: <p>I generated a class from xml (using xsd.exe) and now I have to compare its two instances. The class generated is:</p>
  
  <pre><code> [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
   [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable =    false)]
   public partial class ResultSet
   {
     private ResultSetResult[] resultField;
  
    [System.Xml.Serialization.XmlElementAttribute("Result")]
     public ResultSetResult[] Result
    {
        get
      {
          return this.resultField;
      }
      set
      {
          this.resultField = value;
       }
     }
   }
  
   [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
       public partial class ResultSetResult
    {
      private decimal latitudeField;
      private string precisionField;
  
    public decimal Latitude
    {
       get
      {
          return this.latitudeField;
      }
      set
      {
         this.latitudeField = value;
       }
     }
  
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string precision
    {
       get
       {
          return this.precisionField;
       }
       set
       {
           this.precisionField = value;
       }
      }
     }
  </code></pre>
  
  <p>I know we have to implement a function but this class has partial classes, so how to compare a particular field's value ?</p>
  
  <p>I am tried using</p>
  
  <pre><code>Public static bool PublicInstancePropertiesEqual&lt;T&gt;(T self, T to, params    string[] ignore) where T : class 
  {
      if (self != null &amp;&amp; to != null)
      {
          Type type = typeof(T);
          List&lt;string&gt; ignoreList = new List&lt;string&gt;(ignore);
          foreach (System.Reflection.PropertyInfo pi in   type.GetProperties(System.Reflection.BindingFlags.Public |   System.Reflection.BindingFlags.Instance))
          {
              if (!ignoreList.Contains(pi.Name))
              {
                  object selfValue = type.GetProperty(pi.Name).GetValue(self, null);
                  object toValue = type.GetProperty(pi.Name).GetValue(to, null);
  
                  if (selfValue != toValue &amp;&amp; (selfValue == null ||   !selfValue.Equals(toValue)))
                  {
                      return false;
                  }
              }
          }
          return true;
      }
      return self == to;
  }
  </code></pre>
  
  <p>but the last line self==to gives error (Operator == can not be applied to operands of the type class_name)</p>