Boo AST Attribute Ideas
Here are some ideas I had for handy Boo AST (abstract syntax tree) attributes:[HandleExceptionWithMessageBox]
def Foo():
CallSomething()
DoStuff()
MaybeCrash()
expands todef Foo():
try:
CallSomething()
DoStuff()
MaybeCrash()
except ex:
MessageBox.Show(ex.Message)
Very handy for UI code that calls into business objects that may throw up exceptions. Not having to explicitly write the try…except block is a timesaver!
Also,
class MyForm:
btn = Button()
[HandleEvent(btn.Click)]
def ButtonClicked():
print "button clicked"
expands toclass MyForm:
btn = Button()
def constructor():
btn.Click += ButtonClicked
def ButtonClicked():
print "button clicked"
This allows the event hookup to appear on the handling method, rather than miles away in the constructor. This is great for UI code since it means u can delete a method and know there is not still a line of code else trying to point to it. (So basically is works like the VB.NET "handles" keyword.)
Add a comment
You are not allowed to comment on this entry as it has restricted commenting permissions.