作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有以下代码:
using System
public static class IntEx
{
/// <summary>
/// Yields a power of the given number
/// </summary>
/// <param name="number">The base number</param>
/// <param name="powerOf">the power to be applied on te base number</param>
/// <returns>Powers applied to the base number</returns>
public static IEnumerable<int> ListPowersOf(this int number, int powerOf)
{
for (var i = number; ; i <<= powerOf)
{
yield return i;
}
}
}
我已经在 Powershell (Windows 8) 中加载了 dll。我尝试按以下方式使用它:
$test = 1.ListPowersOf(2)
应该返回@(1, 2, 4, 8, 16...)
相反,它说没有这样的方法。
我尝试了以下方法:
[BaseDllNamespace]::ListPowersOf(1,2)
仍然没有。我在 IntEx 类中没有命名空间。
如何让它工作
最佳答案
试试这个:
[IntEx]::ListPowersOf(1,2)
或
[IntEx] | gm -Static -Type Method
列出可用的静态方法。
您还可以使用反射来获取导出类型的列表,以查看您的类型是否可用:
[Reflection.Assembly]::LoadFile('C:path\to.dll')|select -ExpandProperty ExportedTypes
关于c# - 如何在 Powershell 中使用扩展方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25915450/
我是一名优秀的程序员,十分优秀!