Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reflection 通过PowerShell的反射调用静态方法_Reflection_Powershell - Fatal编程技术网

Reflection 通过PowerShell的反射调用静态方法

Reflection 通过PowerShell的反射调用静态方法,reflection,powershell,Reflection,Powershell,我正在从一个XML文件中读取有关各种对象的信息,需要从PowerShell中实例化并设置这些对象的值 这是一个示例,其中应使用反射检索UInt32.Parse(string)。问题是$mi变量为空: $o = new-object -typename "System.UInt32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" $mi = $o.GetType().GetMethod("P

我正在从一个XML文件中读取有关各种对象的信息,需要从PowerShell中实例化并设置这些对象的值

这是一个示例,其中应使用反射检索
UInt32.Parse(string)
。问题是
$mi
变量为空:

$o = new-object -typename "System.UInt32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
$mi = $o.GetType().GetMethod("Parse", [type[]] @([string].GetType()) )
相应的C#代码起作用:

UInt32 o = 0;
var mi = o.GetType().GetMethod("Parse", new [] {typeof(string)});

有什么想法吗?

你需要使用反射吗?也许您可以使用
$parse=[system.uint32]::parse
$parse.Invoke($arg)