プログラムから、クラス定義に記述されたプロパティ定義を取得する方法
これは InterSystems FAQ サイトの記事です。
クラスに定義されたプロパティの情報については、以下システムクラスを利用して情報を取得できます。
%Dictionary.PropertyDefinition
コード記述例は以下の通りです。
Class ISJ.Sample
{
ClassMethod getPropInfo(classname As %String)
{
set cls=##class(%Dictionary.ClassDefinition).%OpenId(classname,,.status)
if $$$ISERR(status) {
write "指定クラスは存在しません",!
quit // または return
}
set x=cls.Properties
for i=1:1:x.Count() {
// プロパティ情報を取得(%Dictionary.PropertyDefinition)
set prop=x.GetAt(i)
if prop="" {
continue
}
set propname=prop.Name // プロパティ名
set proptype=prop.Type // プロパティタイプ
if propname="" {
continue
}
write propname," ",proptype,!
}
}
}
実行例は以下の通りです。
USER>do ##class(ISJ.Sample).getPropInfo("Taxi.Driver")
DriverID %String
Name %String
Phone %String