예제 #1
0
        static void GenerateAttributes(CodeTypeDeclaration type, RssElementBase element)
        {
            foreach (KeyValuePair <string, string> attr in element.Attributes)
            {
                string rssName  = attr.Key;
                string codeName = CodeNameFromRssName(rssName);

                CodeMemberProperty prop = new CodeMemberProperty();
                prop.Attributes &= ~MemberAttributes.AccessMask;
                prop.Attributes |= MemberAttributes.Public;
                prop.Name        = codeName;
                prop.Type        = new CodeTypeReference(typeof(string));

                prop.GetStatements.Add(new CodeMethodReturnStatement(new CodeMethodInvokeExpression(
                                                                         new CodeBaseReferenceExpression(),
                                                                         "GetAttributeValue",
                                                                         new CodeExpression[1] {
                    new CodePrimitiveExpression(rssName)
                })));

                prop.SetStatements.Add(new CodeMethodInvokeExpression(
                                           new CodeBaseReferenceExpression(),
                                           "SetAttributeValue",
                                           new CodeExpression[2] {
                    new CodePrimitiveExpression(rssName),
                    new CodePropertySetValueReferenceExpression()
                }));

                type.Members.Add(prop);
            }
        }
예제 #2
0
        static void GenerateSetDefaultsMethod(CodeTypeDeclaration type, RssElementBase element)
        {
            CodeMemberMethod m = new CodeMemberMethod();

            m.Name        = "SetDefaults";
            m.Attributes &= ~MemberAttributes.AccessMask;
            m.Attributes &= ~MemberAttributes.ScopeMask;
            m.Attributes |= MemberAttributes.Public | MemberAttributes.Override;

            // attributes' defaults
            foreach (KeyValuePair <string, string> attr in element.Attributes)
            {
                m.Statements.Add(new CodeMethodInvokeExpression(
                                     new CodeBaseReferenceExpression(),
                                     "SetAttributeValue",
                                     new CodeExpression[2] {
                    new CodePrimitiveExpression(attr.Key),
                    new CodePrimitiveExpression(attr.Value)
                }));
            }

            // image defaults if this is channel with an image
            if (element is GenericRssChannel && (element as GenericRssChannel).Image != null)
            {
                m.Statements.Add(new CodeMethodInvokeExpression(
                                     new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "Image"),
                                     "SetDefaults",
                                     new CodeExpression[0]));
            }

            type.Members.Add(m);
        }
예제 #3
0
        internal static XmlNode SaveRssElementAsXml(XmlNode parentNode, RssElementBase element, string elementName)
        {
            XmlDocument doc  = parentNode.OwnerDocument;
            XmlNode     node = doc.CreateElement(elementName);

            parentNode.AppendChild(node);

            foreach (KeyValuePair <string, string> attr in element.Attributes)
            {
                XmlNode attrNode = doc.CreateElement(attr.Key);
                attrNode.InnerText = ResolveAppRelativeLinkToUrl(attr.Value);
                node.AppendChild(attrNode);
            }

            return(node);
        }
예제 #4
0
        static void GenerateCtorsFromAttributes(CodeTypeDeclaration type, RssElementBase element)
        {
            // argless ctor first
            CodeConstructor c0 = new CodeConstructor();

            c0.Attributes &= ~MemberAttributes.AccessMask;
            c0.Attributes |= MemberAttributes.Public;
            type.Members.Add(c0);

            // ctor with attributes as arguments
            if (element.Attributes.Count > 0)
            {
                CodeConstructor cN = new CodeConstructor();
                cN.Attributes &= ~MemberAttributes.AccessMask;
                cN.Attributes |= MemberAttributes.Public;

                // param list
                foreach (KeyValuePair <string, string> attr in element.Attributes)
                {
                    cN.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string),
                                                                             CodeParamNameFromRssName(attr.Key)));
                }

                // ctor body
                foreach (KeyValuePair <string, string> attr in element.Attributes)
                {
                    cN.Statements.Add(new CodeMethodInvokeExpression(
                                          new CodeBaseReferenceExpression(),
                                          "SetAttributeValue",
                                          new CodeExpression[2] {
                        new CodePrimitiveExpression(attr.Key),
                        new CodeArgumentReferenceExpression(CodeParamNameFromRssName(attr.Key))
                    }));
                }

                type.Members.Add(cN);
            }
        }