mercredi 25 novembre 2015

Compare One Model Class to Another C#

At the moment I currently have a CompanyModel that looks like so;

public class CompanyModel
{
    public string CompanyID { get; set; }
    public string CompanyName { get; set; }
    public string CompanyAddr1 { get; set; }
    public string CompanyAddr2 { get; set; }
    public string CompanyTown { get; set; }
    public string CompanyCounty { get; set; }
    public string CompanyPcode { get; set; }
    public string CompanyTelephone { get; set; }
    public string CompanyAltTelephone { get; set; }
    public string CompanyFax { get; set; }
    public string CompanyEmail { get; set; }
    public string CompanyWhoEntered { get; set; }
    public DateTime CompanyDateEntered { get; set; }
    public string CompanyTimeEntered { get; set; }
    public string CompanyGeographicArea { get; set; }
    public string CompanySearchName { get; set; }

}

What I would like to do is initialise two CompanyModels and compare the contents of both to ensure that both Companies have exactly the same data in their fields. Currently I am doing an absolutely horrendous concatenation of If statements as I am unsure of another way. This currently looks like so;

if (eCDetails.CompanyName == cCompanyDetails.CompanyName)
   {
      if (eCDetails.CompanyName == cCompanyDetails.CompanyName)
      {
          if (eCDetails.CompanyAddr1 == cCompanyDetails.CompanyName)
          {

and so on and so forth (it's terrible). Is there an easier to way to ensure that both CompanyModels are equivalent?

Aucun commentaire:

Enregistrer un commentaire