CodeStatement CreateControlVariable (Type type, ControlBuilder builder, CodeMemberMethod method, CodeTypeReference ctrlTypeRef)
{
CodeObjectCreateExpression newExpr = new CodeObjectCreateExpression (ctrlTypeRef);
object [] atts = type != null ? type.GetCustomAttributes (typeof (ConstructorNeedsTagAttribute), true) : null;
if (atts != null && atts.Length > 0) {
ConstructorNeedsTagAttribute att = (ConstructorNeedsTagAttribute) atts [0];
if (att.NeedsTag)
newExpr.Parameters.Add (new CodePrimitiveExpression (builder.TagName));
} else if (builder is DataBindingBuilder) {
newExpr.Parameters.Add (new CodePrimitiveExpression (0));
newExpr.Parameters.Add (new CodePrimitiveExpression (1));
}
method.Statements.Add (new CodeVariableDeclarationStatement (ctrlTypeRef, "__ctrl"));
CodeAssignStatement assign = new CodeAssignStatement ();
assign.Left = ctrlVar;
assign.Right = newExpr;
return assign;
}