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