Question

I want to create a custom attribute that will be applied to classDeclarations. I can enumerate attributes from other methods on the class, but not the classDeclaration itself because it is some sort of special method.

I know it is possible though because SysObsoleteAttribute (called from the kernel) is placed in classDeclarations all over.

In Classes\CustCustomerService\create I just copied the attributes to Classes\CustCustomerService\classDeclaration at the top for this test.

[AifDocumentCreateAttribute, SysEntryPointAttribute(true)]
class CustCustomerService extends AifDocumentService
{

}

I created a static method on a new class:

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)));
    }
}

Then created a job to call it, and you can see how it works for one method, but not the other.

static void Job5(Args _args)
{        
    AttributeReflection::AttribsOfSysEntryPointAttributeOnMethod("CustCustomerService", "create", "SysEntryPointAttribute");
    AttributeReflection::AttribsOfSysEntryPointAttributeOnMethod("CustCustomerService", "classDeclaration", "SysEntryPointAttribute");

}

Any ideas how to enumerate Attributes from the classDeclaration??

Was it helpful?

Solution

The classDeclaration is not a method and cannot be called. Hence your sysDictClass variable is null.

Googling reveals that the getAllAttributes method exits on DictClass:

attribArray = sdm ? sdm.getAllAttributes() : sysDictClass.getAllAttributes();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top