powershell是否具有method_missing()? [英] Does powershell have a method_missing()?

查看:75
本文介绍了powershell是否具有method_missing()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究Powershell的动态功能,我想知道一些事情

I have been playing around with the dynamic abilities of powershell and I was wondering something

powershell中是否有任何类似于Ruby的method_missing()的东西,您可以在其中设置捕获所有方法"来动态处理对象上不存在的方法的调用?

Is there is anything in powershell analogous to Ruby's method_missing() where you can set up a 'catch all method' to dynamically handle calls to non-existant methods on your objects?

推荐答案

不,不是.我怀疑PowerShell的下一个版本将变得与.NET 4中添加的动态调度功能更加一致,但是暂时而言,这在纯PowerShell中是不可能的.

No, not really. I suspect that the next version of PowerShell will become more in line with the dynamic dispatch capabilities added to .NET 4 but for the time being, this would not be possible in pure PowerShell.

尽管我确实记得,有一个类似于.NET的TypeDescriptor中的组件模型,用于创建对象,这些对象向PowerShell动态提供属性和方法.例如,这就是XML元素如何被视为对象的方式.但是,根据我的经验,如果将很多集成所需的类型/方法标记为内部的,则对此的记录很少.

Although I do recall that there is a component model similar to that found in .NET's TypeDescriptor for creating objects that provide properties and methods dynamically to PowerShell. This is how XML elements are able to be treated like objects, for example. But this is poorly documented if at all and in my experience, a lot of the types/methods needed to integrate are marked as internal.

这篇关于powershell是否具有method_missing()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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