Esempio n. 1
0
        public void Process(string instructionContent, CodeNamespace templateNamespace,
                            CodeTypeDeclaration templateType, CodeMemberMethod renderMethod)
        {
            Guard.ArgumentNotNull(instructionContent, "instructionContent");
            Guard.ArgumentNotNull(templateNamespace, "templateNamespace");
            Guard.ArgumentNotNull(templateType, "templateType");
            Guard.ArgumentNotNull(renderMethod, "renderMethod");

            IDictionary <string, string> props = KeyValueParser.Parse(instructionContent);

            // TODO: throw?
            if (props.ContainsKey("namespace"))
            {
                templateNamespace.Imports.Add(
                    new CodeNamespaceImport(props["namespace"]));
            }
        }
Esempio n. 2
0
        public void Process(string instructionContent, CodeNamespace templateNamespace,
                            CodeTypeDeclaration templateType, CodeMemberMethod renderMethod)
        {
            Guard.ArgumentNotNull(instructionContent, "instructionContent");
            Guard.ArgumentNotNull(templateNamespace, "templateNamespace");
            Guard.ArgumentNotNull(templateType, "templateType");
            Guard.ArgumentNotNull(renderMethod, "renderMethod");

            IDictionary <string, string> props = KeyValueParser.Parse(instructionContent);

            if (props.ContainsKey("namespace"))
            {
                templateNamespace.Name = props["namespace"];
            }
            if (props.ContainsKey("classname"))
            {
                templateType.Name = props["classname"];
            }
        }
Esempio n. 3
0
        public void Process(string instructionContent, CodeNamespace templateNamespace,
                            CodeTypeDeclaration templateType, CodeMemberMethod renderMethod)
        {
            Guard.ArgumentNotNull(instructionContent, "instructionContent");
            Guard.ArgumentNotNull(templateNamespace, "templateNamespace");
            Guard.ArgumentNotNull(templateType, "templateType");
            Guard.ArgumentNotNull(renderMethod, "renderMethod");

            IDictionary <string, string> props = KeyValueParser.Parse(instructionContent);

            if (!props.ContainsKey("name") && !props.ContainsKey("type"))
            {
                throw new ArgumentException(Properties.Resources.Template_InvalidPropertyDirective);
            }

            CodeMemberField    fld = new CodeMemberField(props["type"], "_" + props["name"].ToLower());
            CodeMemberProperty cmp = new CodeMemberProperty();

            cmp.Name       = props["name"];
            cmp.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            cmp.Type       = new CodeTypeReference(props["type"]);

            cmp.GetStatements.Add(new CodeMethodReturnStatement(
                                      new CodeFieldReferenceExpression(
                                          new CodeThisReferenceExpression(),
                                          fld.Name
                                          )
                                      ));
            cmp.SetStatements.Add(new CodeAssignStatement(
                                      new CodeFieldReferenceExpression(
                                          new CodeThisReferenceExpression(),
                                          fld.Name
                                          ),
                                      new CodeArgumentReferenceExpression("value")
                                      ));

            templateType.Members.Add(fld);
            templateType.Members.Add(cmp);
        }