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

查看:71
本文介绍了为什么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天全站免登陆