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
Comments
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")
}
Hi Eduard,
Perfect! Just what I wanted. By the way there is a little bug as prop is all lower case in the CONTINE line but 'Prop' everywhere else.
Thanks again
Regards
Mike
If your class inherits properties from another class, substitute %compiledclass for %class in the solution above.