asp.net mvc - Use Method in ViewModel to test if form is dirty -


i created method in viewmodel want test properties viewmodel has in common model , if of values of similar properties different return bool value of true. logic of method looks correct returning false, regardless if true or false.

in code below minimumproductinfo (is saved in database) model , 'this' viewmodel (being returned form) inherets model adds few more fields; why test name of 2 fields before test values.

this code tried:

public bool testifdirty(minimumproductinfo minimumproductinfo) {       type firsttype = this.gettype();      type secondtype = minimumproductinfo.gettype();      foreach (propertyinfo firstpropertyinfo in firsttype.getproperties())      {         foreach (propertyinfo secondpropertyinfo in secondtype.getproperties())         {             if (nameof(firstpropertyinfo.name).equals(secondpropertyinfo.name))             {                 object firstvalue = firstpropertyinfo.getvalue(this, null);                 object secondvalue = secondpropertyinfo.getvalue(minimumproductinfo, null);                 if (!object.equals(firstvalue, secondvalue))                 {                     return true;                 }             }            }     }     return false; } 

what missing in logic?


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -