コード例 #1
0
        ObjectCreateExpression ConvertXmlElementExpression(XmlElementExpression xmlElementExpression)
        {
            var newNode = new ObjectCreateExpression(new TypeReference("XElement"), xmlElementExpression.NameIsExpression ? new List <Expression> {
                xmlElementExpression.NameExpression
            } : Expressions(xmlElementExpression.XmlName));

            foreach (XmlExpression attr in xmlElementExpression.Attributes)
            {
                if (attr is XmlAttributeExpression)
                {
                    var a = attr as XmlAttributeExpression;
                    newNode.Parameters.Add(new ObjectCreateExpression(new TypeReference("XAttribute"), new List <Expression> {
                        new PrimitiveExpression(a.Name),
                        a.IsLiteralValue ? new PrimitiveExpression(ConvertEntities(a.LiteralValue)) : a.ExpressionValue
                    }));
                }
                else if (attr is XmlEmbeddedExpression)
                {
                    newNode.Parameters.Add((attr as XmlEmbeddedExpression).InlineVBExpression);
                }
            }

            foreach (XmlExpression expr in xmlElementExpression.Children)
            {
                XmlContentExpression c = expr as XmlContentExpression;
                // skip whitespace text
                if (!(expr is XmlContentExpression && c.Type == XmlContentType.Text && string.IsNullOrWhiteSpace(c.Content)))
                {
                    newNode.Parameters.Add(ConvertXmlExpression(expr));
                }
            }

            return(newNode);
        }
コード例 #2
0
ファイル: XmlExpressionTests.cs プロジェクト: tris2481/ILSpy
        public void VBNetSimpleCDataTest()
        {
            XmlContentExpression content = ParseUtil.ParseExpression <XmlContentExpression>("<![CDATA[<simple> <cdata>]]>");

            Assert.AreEqual(XmlContentType.CData, content.Type);
            Assert.AreEqual("<simple> <cdata>", content.Content);
            Assert.AreEqual(new Location(1, 1), content.StartLocation);
            Assert.AreEqual(new Location(29, 1), content.EndLocation);
        }
コード例 #3
0
ファイル: XmlExpressionTests.cs プロジェクト: tris2481/ILSpy
        public void VBNetSimplePreprocessingInstructionTest()
        {
            XmlContentExpression content = ParseUtil.ParseExpression <XmlContentExpression>("<?xml version='1.0'?>");

            Assert.AreEqual(XmlContentType.ProcessingInstruction, content.Type);
            Assert.AreEqual("xml version='1.0'", content.Content);
            Assert.AreEqual(new Location(1, 1), content.StartLocation);
            Assert.AreEqual(new Location(22, 1), content.EndLocation);
        }
コード例 #4
0
ファイル: XmlExpressionTests.cs プロジェクト: tris2481/ILSpy
        public void VBNetSimpleCommentTest()
        {
            XmlContentExpression content = ParseUtil.ParseExpression <XmlContentExpression>("<!-- test -->");

            Assert.AreEqual(XmlContentType.Comment, content.Type);
            Assert.AreEqual(" test ", content.Content);
            Assert.AreEqual(new Location(1, 1), content.StartLocation);
            Assert.AreEqual(new Location(14, 1), content.EndLocation);
        }
コード例 #5
0
ファイル: XmlExpressionTests.cs プロジェクト: tris2481/ILSpy
        void CheckContent(INode node, string content, XmlContentType type, Location start, Location end)
        {
            Assert.IsTrue(node is XmlContentExpression);
            XmlContentExpression expr = node as XmlContentExpression;

            Assert.AreEqual(type, expr.Type);
            Assert.AreEqual(content, expr.Content);
            Assert.AreEqual(start, expr.StartLocation);
            Assert.AreEqual(end, expr.EndLocation);
        }
コード例 #6
0
        Expression ConvertXmlContentExpression(XmlContentExpression xmlContentExpression)
        {
            Expression newNode = null;

            switch (xmlContentExpression.Type)
            {
            case XmlContentType.Comment:
                newNode = new ObjectCreateExpression(new TypeReference("XComment"), Expressions(xmlContentExpression.Content));
                break;

            case XmlContentType.Text:
                newNode = new PrimitiveExpression(ConvertEntities(xmlContentExpression.Content));
                break;

            case XmlContentType.CData:
                newNode = new ObjectCreateExpression(new TypeReference("XCData"), Expressions(xmlContentExpression.Content));
                break;

            case XmlContentType.ProcessingInstruction:
                string content = xmlContentExpression.Content.Trim();
                if (content.StartsWith("xml", StringComparison.OrdinalIgnoreCase))
                {
                    XDeclaration decl;
                    try {
                        decl = XDocument.Parse("<?" + content + "?><Dummy />").Declaration;
                    } catch (XmlException) {
                        decl = new XDeclaration(null, null, null);
                    }
                    newNode = new ObjectCreateExpression(new TypeReference("XDeclaration"), Expressions(decl.Version, decl.Encoding, decl.Standalone));
                }
                else
                {
                    string target = content.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault() ?? "";
                    string piData = content.IndexOf(' ') > -1 ? content.Substring(content.IndexOf(' ')) : "";
                    newNode = new ObjectCreateExpression(new TypeReference("XProcessingInstruction"), Expressions(target, piData));
                }
                break;

            default:
                throw new Exception("Invalid value for XmlContentType");
            }
            return(newNode);
        }
コード例 #7
0
        public override object VisitXmlContentExpression(XmlContentExpression xmlContentExpression, object data)
        {
            Expression newNode = ConvertXmlContentExpression(xmlContentExpression);

            if (newNode == null)
            {
                return(base.VisitXmlContentExpression(xmlContentExpression, data));
            }

            ReplaceCurrentNode(newNode);

            if (newNode is ObjectCreateExpression)
            {
                return(base.VisitObjectCreateExpression((ObjectCreateExpression)newNode, data));
            }
            else if (newNode is PrimitiveExpression)
            {
                return(base.VisitPrimitiveExpression((PrimitiveExpression)newNode, data));
            }

            return(null);
        }
コード例 #8
0
ファイル: ResolveVisitor.cs プロジェクト: zz0813/Reflexil
        public override object VisitXmlContentExpression(XmlContentExpression xmlContentExpression, object data)
        {
            switch (xmlContentExpression.Type)
            {
            case XmlContentType.Comment:
                return(CreateResolveResult(new TypeReference("System.Xml.Linq.XComment")));

            case XmlContentType.Text:
                return(CreateResolveResult(new TypeReference("System.Xml.Linq.XText")));

            case XmlContentType.CData:
                return(CreateResolveResult(new TypeReference("System.Xml.Linq.XCData")));

            case XmlContentType.ProcessingInstruction:
                if (xmlContentExpression.Content.StartsWith("xml ", StringComparison.OrdinalIgnoreCase))
                {
                    return(CreateResolveResult(new TypeReference("System.Xml.Linq.XDocumentType")));
                }
                return(CreateResolveResult(new TypeReference("System.Xml.Linq.XProcessingInstruction")));

            default:
                throw new Exception("Invalid value for XmlContentType");
            }
        }
コード例 #9
0
 public virtual object VisitXmlContentExpression(XmlContentExpression xmlContentExpression, object data)
 {
     throw new global::System.NotImplementedException("XmlContentExpression");
 }
コード例 #10
0
 public object VisitXmlContentExpression(XmlContentExpression xmlContentExpression, object data)
 {
     throw new NotImplementedException();
 }