创建 XElement 的子类,该子类仍保留对原始 XElement 的引用并保留树结构

发布于 2024-10-08 16:41:06 字数 406 浏览 0 评论 0原文

首先,让我解释一下我正在使用一个继承 XElement 类的类。新类称为 MXElement。它添加了一些用于浏览 XML 树的新功能,以及一些有关属性的更多信息,但这并不是特别重要。我的问题是我有一个充满 XElement 对象的 XML 树。

但是,当我之前从 XElement 对象创建新的 MXElement 对象时,它只是该对象的副本。这意味着我对此对象所做的任何更改都不会影响原始树。

我想我所要求的是一种构建我的 MXElement 类的功能并保留对原始 XElement 对象的引用的方法。如果可能的话,我真的更愿意保留 MXElement 子类,而不是为 XElement 构建大量扩展方法。

To start things off, let me explain that I'm working with a class that inherits the XElement class. The new class is called MXElement. It adds some new functionality to it for navigating through the XML tree, as well as some more information regarding attributes, but that's not particularly important. My problem is that I have an XML Tree filled with XElement objects.

However, when I create a new MXElement object from the XElement object before, it is just a copy of that object. This means that any changes that I make to this object will not effect the original tree.

I suppose what I'm asking for is a way to build in the functionality for my MXElement class and keep references to the original XElement objects. If possible, I would really prefer to keep MXElement a child class instead of building a lot of extension methods for XElement.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘴硬脾气大 2024-10-15 16:41:06

我重新设计了整个想法,不再使用子类,而是使用 XPath 来修改树。

对于未来的想法,我想知道我原来的问题是否还有解决方案,但这是我为当前问题选择的解决方案。

I reworked the entire idea and instead of using a child class, I used XPath to modify the tree.

For future ideas, I would like to know if there is still a solution to my original problem, but this is the solution I chose for my current problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文