Question

The documentation says this is allowed:

ClassMethod GetContacts() As %ListOfObjects(ELEMENTTYPE="ContactDB.Contact") 
[WebMethod]   

I want to do this:

Property Permissions As %ListOfObjects(ELEMENTTYPE="MyPackage.MyClass");

I get an error:

ERROR #5480: Property parameter not declared: MyPackage.Myclass:ELEMENTTYPE

So, do I really have to create a new class and set the ELEMENTTYPE parameter in it for each list I need?

Was it helpful?

Solution

Correct syntax for %ListOfObjects in properties is this one

Property Permissions As list of MyPackage.MyClass;

OTHER TIPS

Yes, a property does sometimes work differently than a method when it comes to types. That is an issue here, in that you can set a class parameter of the return value of a method declaration in a straightforward way, but that doesn't always work for class parameters on the class of a property.

I don't think the way it does work is documented completely, but here are some of my observations:

You can put in class parameters on a property if the type of the property is a data-type (which are often treated differently than objects).

If you look at the %XML.Adaptor class it has the keyword assignment statement

PropertyClass = %XML.PropertyParameters

This appears to add its parameters to all the properties of the class that declares it as its PropertyClass. This appears to be an example of Intersystems wanting to implement something (an XML adaptor) and realizing the implementation of objects didn't provide it cleanly, so they hacked something new into the class compiler. I can't really find much documentation so it isn't clear if its considered a usable API or an implementation detail subject to breakage.

You might be able to hack something this way - I've never tried anything similar.

A possibly simpler work around might be to initialize the Permissions property in %OnNew and %OnOpen. You will probably want a zero element array at that point anyway, rather than a null.

If you look at the implementation of %ListOfObjects you can see that the class parameter which you are trying to set simply provides a default value for the ElementType property. So after you create an instance of %ListOfObjects you could just set it's ElementType property to the proper element type.

This is a bit annoying, because you have to remember to do it every time by hand, and you might forget. Or a maintainer down the road might not now to do it.

You might hope to maybe make it a little less annoying by creating a generator method that initializes all your properties that need it. This would be easy if Intersystems had some decent system of annotating properties with arbitrary values (so you could know what ElementType to use for each property). But they don't, so you would have to do something like roll your own annotations using an XData block or a class method. This probably isn't worth it unless you have more use cases for annotations than just this one, so I would just do it by hand until that happens, if it ever does.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top