All entries for Wednesday 17 May 2006
May 17, 2006
AssignFields Macro
Another handy Boo macro:class AssignFieldsMacro(AbstractAstMacro):
override def Expand(macro as MacroStatement):
ctor = (macro.ParentNode.ParentNode as Constructor)
b = Block()
for param in ctor.Parameters:
assign = BinaryExpression(
BinaryOperatorType.Assign,
ReferenceExpression("_" + param.Name),
ReferenceExpression(param.Name)
)
b.Add(ExpressionStatement(assign))
return bThis lets me do this:class Foo:
[property(Name)]
_name as string
[property(Age)]
_age as int
[property(Food)]
_food as bool
def constructor(name as string, age as int, food as bool):
AssignFields
# inserts:
# _name = name
# _age = age
# _food = food
f = Foo("hello", 42, true)
print f.Name
print f.Age
print f.Food certainly saves a bit of typing!
Google Trend: C# vs Java
Check out Google Trends ! Very cool way to see what people are searching for…This is C# (in blue) and Java (in red):
Please wait - comments are loading

Loading…