本文整理匯總了C#中System.Xml.Linq.XNode.Copy方法的典型用法代碼示例。如果您正苦於以下問題:C# XNode.Copy方法的具體用法?C# XNode.Copy怎麽用?C# XNode.Copy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.Linq.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.
}
}