可替换方法 / Replaceable methods – ww12345678 的部落格 | AX Helper
最新消息:ww12345678 的部落格重装上线,希望大家继续支持。

可替换方法 / Replaceable methods

网络文摘 William 553浏览 0评论

Chain of command enables wrapping of methods – but you must call next. This ensure the "chain" is not broken, and everyone wrapping the method will indeed be called.

However, sometimes it makes sense to break the chain. Here are some examples where this could be useful:

  • In lookup methods. The base implementation will open a lookup dialog, anyone wrapping will (likely) also open a dialog. Yet the user only expects one lookup.
  • In methods with complex SQL operations. As of now; there are select statements (including delete_from, update_recordset, insert_recordset) we cannot make extensible. One way to work around the limitation is to move the statement to a dedicated method, and make the method replaceable.
  • In conversion methods. Here you can conditionally call next, to skip the base conversion, if your logic can handle the conversion.

In Platform Update 11 – we can now decorate methods with the [Replaceable] attribute. This will relax the compiler, so it doesn't look for the next keyword. Logically, this means that when wrapping a Replaceable method, there is no guarantee that your logic will fire. Someone else might be replacing the method, and breaking the chain.

The author of the code is still in control of which methods are replaceable.

My dear "partner in crime" Vanya Kashperuk has written a great post about the new capability here: http://kashperuk.blogspot.dk/2017/10/development-tutorial-extensibility_7.html

 

 

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址