Question
· Aug 4, 2016

Generic way to test if all the propertiers of an object are null

I need a generic way to check if all the properties on an object instance are null. Has anyone got some code they could share?

I could of course add a method to each class and pass in all the properties and test them but I'm sure there must be a generic way to do this. A generator method perhaps?

Regards

Mike

Discussion (3)1
Log in or sign up to continue

Something like this? I had a similar problem, but the check was required only for part of the properties. If you want all of them, remove the line with continue.

Method IsEmpty() As %Boolean [ CodeMode = objectgenerator ]
{
    For i = 1:1:%class.Properties.Count() {
        Set Prop = %class.Properties.GetAt(i)
        CONTINUE:(Prop.Internal || Prop.Calculated || Prop.ReadOnly || Prop.Private || Prop.Identity)
        
        Do %code.WriteLine(" Quit:.." _ Prop.Name _ "'="""" $$$NO")
    }
    Do %code.WriteLine(" Quit $$$YES")
}