如何从PowerShell调用显式实现的接口方法? [英] How can I call explicitly implemented interface method from PowerShell?

查看:373
本文介绍了如何从PowerShell调用显式实现的接口方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码:

add-type @"
    public interface IFoo
    {
        void Foo();
    }

    public class Bar : IFoo
    {
        void IFoo.Foo()
        {
        }
    }
"@ -Language Csharp

$bar = New-Object Bar
($bar -as [IFoo]).Foo() # ERROR.

错误:


方法调用失败,因为[Bar]
不包含名为Foo的方法。

Method invocation failed because [Bar] doesn't contain a method named 'Foo'.


推荐答案

坏消息:这是一个错误。

Bad news: It's a bug.

https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=249840&SiteID=99

这篇关于如何从PowerShell调用显式实现的接口方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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