当前位置: 首页>>代码示例>>C#>>正文


C# XProcessingInstruction.AddBeforeSelf方法代码示例

本文整理汇总了C#中System.Xml.Linq.XProcessingInstruction.AddBeforeSelf方法的典型用法代码示例。如果您正苦于以下问题:C# XProcessingInstruction.AddBeforeSelf方法的具体用法?C# XProcessingInstruction.AddBeforeSelf怎么用?C# XProcessingInstruction.AddBeforeSelf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.Linq.XProcessingInstruction的用法示例。


在下文中一共展示了XProcessingInstruction.AddBeforeSelf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NodeNoParentAddRemove

                /// <summary>
                /// Tests the AddAfterSelf/AddBeforeSelf/Remove method on Node,
                /// when there's no parent.
                /// </summary>
                /// <param name="context"></param>
                /// <returns></returns>
                //[Variation(Desc = "NodeNoParentAddRemove")]
                public void NodeNoParentAddRemove()
                {
                    // Not allowed if parent is null.
                    int i = 0;
                    while (true)
                    {
                        XNode node = null;

                        switch (i++)
                        {
                            case 0: node = new XElement("x"); break;
                            case 1: node = new XComment("c"); break;
                            case 2: node = new XText("abc"); break;
                            case 3: node = new XProcessingInstruction("target", "data"); break;
                            default: i = -1; break;
                        }

                        if (i < 0)
                        {
                            break;
                        }

                        try
                        {
                            node.AddBeforeSelf("foo");
                            Validate.ExpectedThrow(typeof(InvalidOperationException));
                        }
                        catch (Exception ex)
                        {
                            Validate.Catch(ex, typeof(InvalidOperationException));
                        }

                        try
                        {
                            node.AddAfterSelf("foo");
                            Validate.ExpectedThrow(typeof(InvalidOperationException));
                        }
                        catch (Exception ex)
                        {
                            Validate.Catch(ex, typeof(InvalidOperationException));
                        }

                        try
                        {
                            node.Remove();
                            Validate.ExpectedThrow(typeof(InvalidOperationException));
                        }
                        catch (Exception ex)
                        {
                            Validate.Catch(ex, typeof(InvalidOperationException));
                        }
                    }
                }
开发者ID:johnhhm,项目名称:corefx,代码行数:60,代码来源:SDMNode.cs

示例2: NodeNoParentAddRemove

        public void NodeNoParentAddRemove()
        {
            // Not allowed if parent is null.
            int i = 0;
            while (true)
            {
                XNode node = null;

                switch (i++)
                {
                    case 0:
                        node = new XElement("x");
                        break;
                    case 1:
                        node = new XComment("c");
                        break;
                    case 2:
                        node = new XText("abc");
                        break;
                    case 3:
                        node = new XProcessingInstruction("target", "data");
                        break;
                    default:
                        i = -1;
                        break;
                }

                if (i < 0)
                {
                    break;
                }

                Assert.Throws<InvalidOperationException>(() => node.AddBeforeSelf("foo"));
                Assert.Throws<InvalidOperationException>(() => node.AddAfterSelf("foo"));
                Assert.Throws<InvalidOperationException>(() => node.Remove());
            }
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:37,代码来源:SDMNode.cs


注:本文中的System.Xml.Linq.XProcessingInstruction.AddBeforeSelf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。