c# - fastest way to compare 2 objects excluding a few properties? -


i have site users upload data , want update data properties have been changed. comparing 2 objects of same type changes , need exclude few properties such modifiedon date.

here code far using reflection:

 private bool haschanges(object oldobject, object newobject)         {             var oldprops = (from p in oldobject.gettype().getproperties() select p).tolist();             var newprops = (from p in newobject.gettype().getproperties() select p).tolist();             bool ischanged = false;             foreach (propertyinfo in oldprops)             {                 if (checkcolumnnames(i.name))                 {                     var newinfo = (from x in newprops x.name == i.name select x).single();                     var oldval = i.getvalue(oldobject, null);                     var newval = newinfo.getvalue(newobject, null);                      if (newval == null || oldval == null)                     {                         if (newval == null && oldval != null)                         {                             ischanged = true;                             return true;                         }                         if (oldval == null && newval != null)                         {                             ischanged = true;                               return true;                         }                     }                     else                     {                         if (!newval.equals(oldval))                         {                             ischanged = true;                          return true;                         }                     }                 }             }              return ischanged;         } 

i ignore columns method:

private bool checkcolumnnames(string colname)         {             if (                 colname.tolower() == "productid" ||                 colname.tolower() == "customerid" ||                 colname.tolower() == "shiptoid" ||                 colname.tolower() == "parentchildid" ||                 colname.tolower() == "categoryitemid" ||                  colname.tolower() == "volumepricingid" ||                 colname.tolower() == "tagid" ||                 colname.tolower() == "specialprice" ||                 colname.tolower() == "productsmodifierid" ||                 colname.tolower() == "modifierlistitemid" ||                 colname.tolower() == "modifierlistid" ||                 colname.tolower() == "categoryitemid" ||                 colname.tolower() == "createdon" ||                 colname.tolower() == "createdby" ||                 colname.tolower() == "modifiedon" ||                 colname.tolower() == "modifiedby" ||                 colname.tolower() == "deletedon" ||                 colname.tolower() == "deletedby" ||                 colname.tolower() == "appendproductmodifiers" ||                 colname.tolower() == "introdate" ||                 colname.tolower() == "id" ||                 colname.tolower() == "discontinued" ||                 colname.tolower() == "stagingcategories"                 )                 return false;              return true;         } 

this has been working except have users comparing 50,000+ items in single upload taking long time.

is there faster way accomplish this?

it faster if used reflection create , compile method using above logic. should faster reflecting on each object.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -