假设我有几个从MyAbstractClass扩展的类,每个类都包含MyAbstractClass上不存在的属性。我如何从其中一个类获得属性值?
像这样的东西:(伪代码)
Method GetPropertyValue(myAbstractClass As MyAbstractClass) As %String
{
Set myPropertyValue = myAbstractClass.GetType().GetProperty("MyProperty").GetValue();
Quit myPropertyValue
}
到目前为止,我有这个:
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?
}
}
}
}
答案 0 :(得分:1)
Method GetPropertyValue(PropertyName)
{
Q $PROPERTY(##this,Name)
}
在older versions缓存中,您将使用$ ZOBJPROPERTY而不是$ PROPERTY。显然在2010.1版之前。
答案 1 :(得分:1)
您不需要在缓存中转换类型。
如果您需要获取已知属性,可以使用通常的语法:
Set myPropertyValue = myAbstractClass.MyProperty
如果你需要获得一个未知的财产,你可以使用$ property function
Set myPropertyName = "PropertyNumber"_i
Set myPropertyValue = $property(myAbstractClass,myPropertyName)