示例#1
0
        protected CodeConstructor EmitTemplate(CodeTypeDeclaration ctd)
        {
            EmitAttribute(ctd);

            // A(n optional) field pointing to our bound structure

            if (UsesStructure)
            {
                CodeMemberField f = new CodeMemberField();
                f.Name       = "stmpl";
                f.Attributes = MemberAttributes.Private;
                f.Type       = NS.ParamsType.AsCodeDom;
                ctd.Members.Add(f);
            }

            // The template apply method.

            CodeMemberMethod meth = new CodeMemberMethod();

            meth.Name       = "ApplyTemplate";
            meth.Attributes = MemberAttributes.Public | MemberAttributes.Override;
            meth.ReturnType = null;
            meth.Parameters.Add(CDH.Param(typeof(TargetBuilder), "tb"));

            CDH.EmitBaseChainVoid(meth);

            CodeVariableReferenceExpression tb = CDH.VRef("tb");

            if (UsesStructure)
            {
                info.Converter = delegate(string val) {
                    return(NS.MakeTargetNameExpr(val, CDH.ThisDot("stmpl"), null));
                };
            }

            info.EmitInfo(meth, tb);
            ctd.Members.Add(meth);

            // Constructor

            return(EmitConstructor(ctd));
        }