本文整理汇总了C#中XNode.Copy方法的典型用法代码示例。如果您正苦于以下问题:C# XNode.Copy方法的具体用法?C# XNode.Copy怎么用?C# XNode.Copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XNode
的用法示例。
在下文中一共展示了XNode.Copy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Rewrite
// CONSIDER: could add a depth count and just not rewrite below that depth.
private XNode[] Rewrite(XNode node, string currentXmlFilePath, CSharpSyntaxNode originatingSyntax)
{
cancellationToken.ThrowIfCancellationRequested();
string commentMessage = null;
if (node.NodeType == XmlNodeType.Element)
{
XElement element = (XElement)node;
if (ElementNameIs(element, DocumentationCommentXmlNames.IncludeElementName))
{
XNode[] rewritten = RewriteIncludeElement(element, currentXmlFilePath, originatingSyntax, out commentMessage);
if (rewritten != null)
{
return rewritten;
}
}
}
XContainer container = node as XContainer;
if (container == null)
{
Debug.Assert(commentMessage == null, "How did we get an error comment for a non-container?");
return new XNode[] { node.Copy(copyAttributeAnnotations: false) };
}
IEnumerable<XNode> oldNodes = container.Nodes();
// Do this after grabbing the nodes, so we don't see copies of them.
container = container.Copy(copyAttributeAnnotations: false);
// WARN: don't use node after this point - use container since it's already been copied.
if (oldNodes != null)
{
XNode[] rewritten = RewriteMany(oldNodes.ToArray(), currentXmlFilePath, originatingSyntax);
container.ReplaceNodes(rewritten);
}
// NOTE: we may modify the values of cref attributes, so don't do this until AFTER we've
// made a copy. Also, we only care if we're included text - otherwise we've already
// processed the cref.
if (container.NodeType == XmlNodeType.Element && originatingSyntax != null)
{
XElement element = (XElement)container;
foreach (XAttribute attribute in element.Attributes())
{
if (AttributeNameIs(attribute, DocumentationCommentXmlNames.CrefAttributeName))
{
BindAndReplaceCref(attribute, originatingSyntax);
}
else if (AttributeNameIs(attribute, DocumentationCommentXmlNames.NameAttributeName))
{
if (ElementNameIs(element, DocumentationCommentXmlNames.ParameterElementName) ||
ElementNameIs(element, DocumentationCommentXmlNames.ParameterReferenceElementName))
{
BindName(attribute, originatingSyntax, isParameter: true);
}
else if (ElementNameIs(element, DocumentationCommentXmlNames.TypeParameterElementName) ||
ElementNameIs(element, DocumentationCommentXmlNames.TypeParameterReferenceElementName))
{
BindName(attribute, originatingSyntax, isParameter: false);
}
}
}
}
if (commentMessage == null)
{
return new XNode[] { container }; // Already copied.
}
else
{
XComment failureComment = new XComment(commentMessage);
return new XNode[] { failureComment, container }; // Already copied.
}
}