lundi 29 octobre 2018

c# reflection comparing 2 objects with boolean properties

I have two objects with several properties that are of type boolean. The properties are identical in terms of naming and I just want to make sure they are equal. I do a lot of these checks and want to know if anyone has any suggestion of a method that can do the following code in one step but is dynamic enough to check the property options by name if they have the same name?

 if (options != null && other != null)
            return options.Quantities == other.Quantities &&
                   options.SKUEntityKey == other.SKUEntityKey &&
                   options.LineItemType_Type == other.LineItemType_Type &&
                   options.SKUIdentifier == other.SKUIdentifier &&
                   options.Identifier == other.Identifier;

If what I'm asking isn't clear please let me know





Aucun commentaire:

Enregistrer un commentaire