强制编译器将标识符视为包名

Force compiler to treat identifier as package name

TestApi Class:

package api;
class TestApi {}

另一个Class

package somewhere.else;
class AnotherClass
{
    var api:SomeType;

    function problem()
    {
        api.TestApi; 
        // Compiler error: SomeType has no field TestApi


    }
}

在上面的示例中,我想强制编译器将 api 视为包名而不是变量,因此 api.TestApi 指的是 class 而不是成员api 变量。我需要这样做,因为我在宏内部构建表达式并且无法使用导入语句。有什么想法吗?

您应该可以使用伪包 std 解决此问题,该伪包解析为 API 根:(1)()

var api:SomeType;
function problem() {
    std.api.TestApi;
}

另一个例子:

class Test {
    static var Test = 42;
    static function main() {
        trace(Test);           // 42
        trace(std.Test.Test);  // 42
    }
}

(see it in action)