How to set the Attribute VB_PredeclaredId using RubberDuck '@PredeclaredID

て烟熏妆下的殇ゞ 提交于 2019-12-13 14:43:16

问题


As a Rubberduck and OOP newbie I'm still learning how to use the software and take advantage of the programming techniques

First time I saw about folder annotations (https://github.com/rubberduck-vba/Rubberduck/wiki/Using-@Folder-Annotations) it was quite intuitive how it worked.

But then came the VB_Attribute Annotations (https://github.com/rubberduck-vba/Rubberduck/wiki/VB_Attribute-Annotations) which I didn't quite know how to made them work.

Hope this saves some time to peolple looking to use this feature

EDIT:

To contextualize the need of Attributes, here is a great post I found by Christopher J. McClellan

https://christopherjmcclellan.wordpress.com/2015/04/21/vb-attributes-what-are-they-and-why-should-we-use-them/

And the beauty about RubberDuck is that you don't need to do the Export/Edit/Import part manually, and it does it with a couple of clicks as described in the answer bellow.


回答1:


To apply a predeclared id (set it to true) follow this steps:

1- Enable the Rubberduck code explorer window

2- At the top of the class, add the text: '@PredeclaredID

Note: In the Code Explorer Window you can see when a Class has a Predeclared Attribute set to true because it has (PredeclaredId) in parenthesis next to its name

3- Launch Rubberduck "Code inspections"

4- Hit the "Refresh" button

5- In the "filter by descripcion" textbox type "pred"

6- Select the Issue and click the "fix" button

7- Select "Adjust attributes value"

Now the code explorer should show the "Predeclared" tag next to the class name



来源:https://stackoverflow.com/questions/58600560/how-to-set-the-attribute-vb-predeclaredid-using-rubberduck-predeclaredid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!