gpt4 book ai didi

.net - Powershell:列出 .net 组件的成员

转载 作者:行者123 更新时间:2023-12-04 14:44:19 30 4
gpt4 key购买 nike

我正在尝试构建一个脚本,该脚本将为我提供 .net 组件中 dll 的方法列表。

这是我到目前为止所做的:

Param([String]$path)
if($path.StartsWith("["))
{
$asm = [Reflection.Assembly]::LoadWithPartialName($path)
$asm.GetTypes() | select Name, Namespace | sort Namespace | ft -groupby Namespace
}
else
{
$asm = [Reflection.Assembly]::LoadFile($path)
$asm.GetTypes() | select Name, Namespace | sort Namespace | ft -groupby Namespace
}

所以基本上脚本的第二部分(当提供 dll 的路径时)工作得很好;

运行 '.\GetDllMethods.ps1 -path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"' 将为我提供 WinSCP dll 的所有成员。

我想用脚本的第一部分实现的是通过使用以下内容提供 .net 组件的名称来获得相同的结果:

.\GetDllMethods.ps1 -path "[System.IO.StreamWriter]"

获取 StreamWriter 组件的所有成员。

但我在这里得到一个空异常..有什么提示吗?

最佳答案

您可以使用 powershell cmdlet get-member

PS>[system.net.webclient]|get-member  -MemberType method                                                                              


TypeName : System.RuntimeType

Name MemberType Definition
---- ---------- ----------
AsType Method type AsType()
Clone Method System.Object Clone(), System.Object ICloneable.Clone()

...

我们可以看到有一个 GetMethods 方法,所以尝试:
[system.net.webclient].GetMethods()    

关于.net - Powershell:列出 .net 组件的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26297314/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com