Reputation: 11287
Let's say I have several classes that extend from MyAbstractClass each containing their own properties that do not exist on MyAbstractClass. How would I get a property value from one of those classes?
Something like this: (pseudocode)
Method GetPropertyValue(myAbstractClass As MyAbstractClass) As %String
{
Set myPropertyValue = myAbstractClass.GetType().GetProperty("MyProperty").GetValue();
Quit myPropertyValue
}
So far I have this:
Method GetPropertyValue(argBusinessObject As BusinessObject)
{
// get class name.
set className = argBusinessObject.%PackageName()_"."_argBusinessObject.%ClassName()
set dictionary = ##class(%Dictionary.ClassDefinition).%OpenId(className)
if (dictionary '= "")
{
for index=1:1:dictionary.Properties.Count()
{
#dim clsPropDef As %Dictionary.PropertyDefinition
// Get the property name from the class
set clsPropDef = dictionary.Properties.GetAt(index)
if (..PropertyName = clsPropDef.Name) {
// we have the property
// Set the propName so that it gets included
// now what?
}
}
}
}
Upvotes: 1
Views: 481
Reputation: 2900
Method GetPropertyValue(PropertyName)
{
Q $PROPERTY(##this,Name)
}
In older versions of Cache you would use $ZOBJPROPERTY instead of $PROPERTY. Apparently prior to version 2010.1.
Upvotes: 1
Reputation: 2553
You don't need to cast types in Cache.
If you need to get a known property, you may use usual syntax:
Set myPropertyValue = myAbstractClass.MyProperty
If you need to get a property which is not known, you may use $property function
Set myPropertyName = "PropertyNumber"_i
Set myPropertyValue = $property(myAbstractClass,myPropertyName)
Upvotes: 1