vendredi 1 mai 2015

c# Check specific Duplicate values from two object using reflection

public class DuplicateSubmissionField : BaseClass
    {
        public virtual string Name { get; set; }
    }

I have List I have Two objects

public class AdhocRequestModel : BaseClass
    {
        public virtual string RequestId { get; set; }

        public virtual string CaseName { get; set; } 

         public virtual string RegistryNumber { get; set; }      
         ........        
         ....       
    }



public class Case : BaseClass
    {
        public virtual string RequestId { get; set; }

        public virtual string CaseName { get; set; } 

        public virtual string RegistryNumber { get; set; }       
         .......         
         ....
    }

My list of DuplicateSubmissionField contains the List of filed I have check between two object . So I call a method to get List and than I check Duplicate values from both the object

.

I want make something dynamic using reflection. Something Like this ..

foreach (var duplicateSubmissionFieldAssoc in duplicateSubmissionFieldAssocs)
                {
                    var recordsvalue =
                        record.GetType()
                            .GetProperty(duplicateSubmissionFieldAssoc.DuplicateSubmissionField.Name)
                            .GetValue(record, null);
                    var casevalue =
                       cCase.GetType()
                           .GetProperty(duplicateSubmissionFieldAssoc.DuplicateSubmissionField.Name)
                           .GetValue(cCase, null);

                    if (recordsvalue != casevalue)
                    {
                        return true;
                    }

                }





Aucun commentaire:

Enregistrer un commentaire