AS 3中是否有装饰器/宏/注释?

Han*_*etz 0 apache-flex actionscript code-generation

我正在寻找相似的Python装饰器/ Lisp宏/ Java注释(是的,我知道这些不一定等同于它们)在Actionscript中.提供类似功能的工具也很棒(我在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;
  }
  //...
}
Run Code Online (Sandbox Code Playgroud)

因为我已经在函数声明中有了远程函数的参数和返回类型,所以只需添加URL后缀就好了,就像这样(Python启发的伪代码):

@remotify("/get")
public function usrGet(ix:int):User { }
Run Code Online (Sandbox Code Playgroud)

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

cli*_*ers 6

您可以在ActionScript中添加所谓的"元数据",如下所示:

[Remotify(prop="value")]
Run Code Online (Sandbox Code Playgroud)

更多信息在这里:

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