Question Maxime LACH · Mars 20, 2024

Comment comparer deux Registered Object

J'aimerai comparer deux "Registered Object" et lister chaque propriété différente

Pour le moment j'ai ce code :

ClassMethod AssertObjectEquals(object As%RegisteredObject, objectToCompare As%RegisteredObject, Output msg As%String) As%Status
{
        Set returnValue = 1// check if same classSet className = $CLASSNAME(object)
        If (className '= $CLASSNAME(objectToCompare)) {
                Set returnValue = 0Set difference = "not same class"
        }

        If (returnValue) {
                // Get the definition to browse propertiesSet classDef = ##class(%Library.ClassDefinition).%OpenId(className)
                Set propertiesDef = classDef.Properties
                // Check the value for each propertySet difference = ""For i = 1:1:propertiesDef.Count() {
                        Set propertyName = propertiesDef.GetAt(i).Name
                        Set propertyValue = $PROPERTY(object,propertyName)
                        // if different, supply the variable difference with the name of property + valueIf ((propertyValue '= "") && (propertyValue '= $PROPERTY(objectToCompare,propertyName)))
                        {
                                Set difference = difference _ "; " _ propertyName _ " = " _ propertyValue
                        }
                }
        }
        if difference = ""
                {Set msg = "equal"}
        else {
                Set msg = difference
        }
        Return$$$OK
}

Mais cela ne prend pas en compte les propriétés complexes telles que les listes, les tableaux ou les objets.
Quelqu’un a-t-il une idée pour compléter la méthode de classe ou une autre solution totalement différente ?
Merci d’avance !