我想创建一个将应用于classDeclarations的自定义属性。我可以枚举类中其他方法的属性,但不能枚举classDeclaration本身,因为它是某种特殊方法。
我知道这是有可能的,因为SysObsoleteAttribute(从内核调用)始终放置在classDeclarations中。
在此,Classes\CustCustomerService\create
我只是将属性复制Classes\CustCustomerService\classDeclaration
到此测试的顶部。
[AifDocumentCreateAttribute, SysEntryPointAttribute(true)]
class CustCustomerService extends AifDocumentService
{
}
我在新类上创建了一个静态方法:
static public void AttribsOfSysEntryPointAttributeOnMethod
(
str _sNameOfClass,
str _sNameOfMethod,
str _nameOfAttribute
)
{
int nClassId;
SysDictMethod sdm;
Object attributeAsObject;
SysDictClass sysDictClass;
Array attribArray = new Array(Types::Class);
int i;
nClassId = Global::className2Id(_sNameOfClass);
sysDictClass = new SysDictClass(nClassId);
sdm = new SysDictMethod(UtilElementType::ClassInstanceMethod, nClassId, _sNameOfMethod);
attribArray = sdm.getAllAttributes();
if (attribArray)
{
for (i=1; i<=attribArray.lastIndex(); i++)
{
attributeAsObject = attribArray.value(i);
info(strFmt("[%3] Attrib Class Id: %1 [%2]", classIdGet(attributeAsObject), classId2Name(classIdGet(attributeAsObject)), _sNameOfMethod));
}
}
else
{
// Unable to get attributes, try another way
error(strFmt("Unable to retrieve attribute array for method %1", sdm.name()));
// It is, so let's try and enumerate ALL attributes and output them directly from class dec
sdm = sysDictClass.objectMethodObject(1);
if (attribArray)
{
for (i=1; i<=attribArray.lastIndex(); i++)
{
attributeAsObject = attribArray.value(i);
info(strFmt("[%3] Attrib Class Id: %1 [%2]", classIdGet(attributeAsObject), classId2Name(classIdGet(attributeAsObject)), _sNameOfMethod));
}
}
else
error(strFmt("Still unable to retrieve attribute array for method %1", sysDictClass.objectMethod(1)));
}
}
然后创建一个作业来调用它,您可以看到它对一种方法的工作原理,而对另一种方法却没有。
static void Job5(Args _args)
{
AttributeReflection::AttribsOfSysEntryPointAttributeOnMethod("CustCustomerService", "create", "SysEntryPointAttribute");
AttributeReflection::AttribsOfSysEntryPointAttributeOnMethod("CustCustomerService", "classDeclaration", "SysEntryPointAttribute");
}
任何想法如何从classDeclaration枚举属性?
该classDeclaration
不是方法,不能被调用。因此,您的sysDictClass
变量为null。
谷歌搜索显示该getAllAttributes
方法在DictClass
以下位置退出:
attribArray = sdm ? sdm.getAllAttributes() : sysDictClass.getAllAttributes();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句