什么是实际使用的"动态"在C#4.0的变量? [英] What is the practical use of "dynamic" variable in C# 4.0?

查看:99
本文介绍了什么是实际使用的"动态"在C#4.0的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 :)

这篇关于什么是实际使用的"动态"在C#4.0的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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