【问题标题】:Are there Decorators / Macros / Annotations in AS 3?AS 3 中是否有装饰器/宏/注释?
【发布时间】:2009-06-10 09:01:24
【问题描述】:

我正在 Actionscript 中寻找 Python 装饰器/Lisp 宏/Java 注释的等价物(是的,我知道它们本身不一定是等价的)。提供类似功能的工具也会很棒(我在 Linux 上使用适用于 Eclipse 的 Flex Builder 插件)。

我正在编写一个 Flex 应用程序,这是我想要完成的:

我已将各种远程功能集封装在单独的类中(有时称为“消息传递网关”或“远程代理”),其中每个方法都反映服务器上的一个方法,如下所示:

class UserManagementService extends MyHttpService {
  //...
  private final _urlBase:String = "http://example.com/services/users"
  //...

  public function usrGet(ix:int):User
  {
     url = urlBase + "/get";
     mp:Dictionary = new Dictionary();
     mp["ix"] = ix;
     result:User = this._service.varSend(url, this.sEncodeParams(mp), Class("User"));
     return result;
  }
  //...
}

由于我在函数声明中已经有了远程函数的参数和返回类型,因此最好添加 URL 后缀,如下所示(Python 启发的伪代码):

@remotify("/get")
public function usrGet(ix:int):User { }

现在,那不是很整洁吗? ;-)

【问题讨论】:

    标签: apache-flex actionscript code-generation


    【解决方案1】:

    您可以像这样在 ActionScript 中添加所谓的“元数据”:

    [Remotify(prop="value")]
    

    更多信息在这里:

    http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&productId=2&postId=11907

    【讨论】:

    • 酷,我不知道这些实际上是可定制的。我看看能不能达到我想要的效果。
    • 是的,您只需要添加一个特殊的编译器参数,以便信息在运行时可用,然后使用 describeType() 检索它。我链接的文章非常简单。祝你好运。 :)
    猜你喜欢
    • 2013-02-10
    • 2021-11-20
    • 2023-03-23
    • 2022-09-21
    • 2016-09-16
    • 2019-11-13
    • 2019-08-16
    • 1970-01-01
    • 2013-02-27
    相关资源
    最近更新 更多