为什么XmlDocument在.NET 4中是动态的? [英] Why isn't XmlDocument dynamic in .NET 4?

查看:119
本文介绍了为什么XmlDocument在.NET 4中是动态的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望看到使用动态的区域之一是XML。我认为这将使XML处理代码更容易写入,我相信我在C#4出现之前看到了一些例子,并提到了作为此功能的使用之一。

One of the areas where I would like to see the use of dynamic is XML. I think it would make XML processing code simpler to write and I believe I saw some examples on that before C# 4 came out and it's mentioned in this answer as one of the uses of this feature.

所以,我的问题是这样的:为什么不是 XmlDocument (或 XDocument )是动态的,或者为什么不会有一些C#4中的动态XML操作的新类?

So, my question is this: why wasn't the XmlDocument (or XDocument) made dynamic, or why isn't there some new class for dynamic XML manipulation in C# 4?

这对我来说更奇怪,当我认为在PowerShell中, XmlDocument 是动态,代码如 $ xmlDoc.root.subnode.subsubnode 在那里工作。

This is even more strange to me, when I consider that in PowerShell, XmlDocument is dynamic, code like $xmlDoc.root.subnode.subsubnode works there.

推荐答案

给出一些评论,让我提供一个替代答案。原来的问题是为什么XmlDocument在.NET 4中不是动态的。虽然可以通过 IDynamicMetaObjectProvider 将现有的xml文档类添加expando属性功能,但这样做可能是一个不小的努力。将来自System.Xml的原始Xml对象模型完全动态化将需要对Xml框架进行一些广泛的修改,并且需要将IDynamicMetaObjectProvider添加到涉及的每个对象。这包括XmlDocument,XmlElement,XmlAttribute,XmlNode以及所有其他xml内容类型,如注释,文本节点等。此外,涉及查询和处理的大量支持基础架构,内部类型等元素和属性和值也需要被修改(打开反射器,并看看System.Xml ...超过一半的类型是内部的,它们都是高度相互依赖的和可用的公共类型。)

Given some of the comments, let me provide an alternative answer. The original question asked why XmlDocument was not dynamic in .NET 4. While it may be possible to add "expando" property capability to the existing xml document classes via IDynamicMetaObjectProvider, doing so is likely a non-trivial endeavor. Making the original Xml object model from System.Xml fully dynamic would require some extensive modification of the Xml framework, and would require that IDynamicMetaObjectProvider be added to every object that is involved. That includes XmlDocument, XmlElement, XmlAttribute, XmlNode, and all of the other xml content types like comments, text nodes, etc. In addition, a considerable amount of support infrastructure, internal types, etc. that are involved in the lookup and processing of elements and attributes and values would also need to be modified (open up Reflector, and take a look at System.Xml...more than half of the types are internal, and they are all highly interdependent with each other and the available public types.)

同样重要的是考虑在.NET中实现Xml的expando属性的适当范围。你会停止在XmlDocument和相关类型?或者更适合包括XPath,Xml Schema等?

It is also important to consider the proper scope of implementing expando properties for Xml in .NET. Would you stop at just the XmlDocument and related types? Or would it be more appropriate to include XPath, Xml Schema, etc.?

为了回答原始问题,为什么XmlDocument在.NET 4中是动态的?,我认为简单的答案是:实现完全动态的API,或者在这里的Xml的情况下,提供任意xml文档的属性扩展的API远不是一件简单的任务。鉴于微软的工作伦理,他们无法轻松地处理这样的任务是合乎逻辑的,如果他们试图为Xml框架实现expando属性,我希望并期望它能够在同样程度的仔细关注和关心他们给了.NET的其余部分。

To answer the original question, "Why isn’t XmlDocument dynamic in .NET 4?", I think the simple answer is this: Implementing fully 'dynamic' API's, or in the case of Xml here, API's that provide property expansion of arbitrary xml documents, is far from a trivial task. Given Microsoft's work ethic, it makes logical sense that they would not approach such a task lightly, and if they attempt to implement expando properties for the Xml framework, I would hope and expect it to be done with the same level of careful attention and care they give to the rest of .NET.

这篇关于为什么XmlDocument在.NET 4中是动态的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆