什么是实际使用的"动态"在C#4.0的变量?变量、实际、动态、QUOT

2023-09-02 10:38:47 作者:打小就帅怪我咯

什么是他们的使用,如果当你调用方法时,它可能不存在吗?

What is their use if when you call the method, it might not exist?

这是否意味着你将能够动态对象的动态创建的方法?

Does that mean that you would be able to dynamically create a method on a dynamic object?

什么是实际使用的呢?

推荐答案

您不会真的能够动态地创建方法 - 但你可以得到的一个实现 IDynamicMetaObject (往往通过延长 DynamicObject )响应的,如果该方法存在的。

You won't really be able to dynamically create the method - but you can get an implementation of IDynamicMetaObject (often by extending DynamicObject) to respond as if the method existed.

用途:

在对COM编程用微弱的API对象(如办公) 在调用到动态语言如Ruby / Python的 可能使探究性的对象 - 想象类似XPath的查询,但通过一个方法/属性调用如 document.RootElement.Person [5] .Name点[属性] 毫无疑问,更多的我们还没有想到的:) Programming against COM objects with a weak API (e.g. office) Calling into dynamic languages such as Ruby/Python Potentially making "explorable" objects - imagine an XPath-like query but via a method/property calls e.g. document.RootElement.Person[5].Name["Attribute"] No doubt many more we have yet to think of :)