【发布时间】:2010-11-10 22:47:55
【问题描述】:
我无法弄清楚如何让 Powershell 调用我班级的索引器。该类看起来像这样(大大简化):
public interface IIntCounters
{
int this[string counterName] { get; set; }
}
public class MyClass : IIntCounters
{
public IIntCounters Counters { get { return this; } }
int IIntCounters.this[string counterName]
{ get { ...return something... } }
}
如果我新建这个类,我不能只在它上面使用方括号运算符 - 我会收到“无法索引”错误。我还尝试使用 get_item(),这是 Reflector 向我展示的索引器最终在程序集中的样子,但这让我出现“不包含名为 get_item 的方法”的错误。
更新:这似乎特定于我使用显式接口。所以我的新问题是:有没有办法让 Powershell 在不切换显式接口的情况下查看索引器? (如果可能的话,我真的不想修改这个程序集。)
【问题讨论】:
标签: c# powershell