小编Yak*_*een的帖子

将XAttribute插入指定位置的现有XElement

以下是用于创建具有属性的元素的简化用例代码示例

        XElement element =
            new XElement(
                "Test",
                new XAttribute("Attr1", "value1"),
                new XAttribute("Attr3", "value3")
            );

        element.Add(new XAttribute("Attr2", "value2"));
Run Code Online (Sandbox Code Playgroud)

如何实现在Attr1之后添加Attr2以产生这样的输出?

        <Test Attr1="value1" Attr2="value2" Attr3="value3" />
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏.谢谢

这是接受的答案中提到的扩展方法:

public static void AddAfterSelf(this XAttribute self, XAttribute value)
{
    if (self == null) throw new ArgumentNullException("self");
    if (value == null) throw new ArgumentNullException("value");
    if (self.Parent == null) throw new ArgumentException("Attribute does not belong to any element.");

    XElement e = self.Parent;
    var attributes = new List<XAttribute>(e.Attributes());
    int idx = attributes.IndexOf(self);

    attributes.Insert(idx + 1, value);
    e.RemoveAttributes();
    e.Add(attributes); …
Run Code Online (Sandbox Code Playgroud)

.net c# xml linq linq-to-xml

5
推荐指数
1
解决办法
6226
查看次数

如何在graphviz中绘制分支架构图

任何暗示如何以附加图像的精神绘制分支模式的提示都受到欢迎.请注意,我想在graphviz中进行快速编辑和将来的更改.

例

version-control dot graphviz

5
推荐指数
2
解决办法
2502
查看次数

标签 统计

.net ×1

c# ×1

dot ×1

graphviz ×1

linq ×1

linq-to-xml ×1

version-control ×1

xml ×1