1

假设我有几个从 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?
            }
        }
    }
}
4

2 回答 2

1
Method GetPropertyValue(PropertyName)
{
  Q $PROPERTY(##this,Name)
}

旧版本的 Cache 中,您将使用 $ZOBJPROPERTY 而不是 $PROPERTY。显然在版本 2010.1 之前。

于 2013-02-12T17:57:25.637 回答
1

您不需要在缓存中转换类型。

如果你需要得到一个已知的属性,你可以使用通常的语法:

Set myPropertyValue = myAbstractClass.MyProperty

如果需要获取未知的属性,可以使用 $property 函数

Set myPropertyName = "PropertyNumber"_i
Set myPropertyValue = $property(myAbstractClass,myPropertyName)
于 2013-02-12T22:05:19.027 回答