gpt4 book ai didi

powershell - 如何在Powershell中消除Type.GetProperty方法的歧义?

转载 作者:行者123 更新时间:2023-12-03 00:50:13 24 4
gpt4 key购买 nike

我正在尝试创建一个Powershell脚本来执行C#代码in this answer的工作。

当我上线时

$type = ($fieldlink).GetType()
$propInfo = $type.GetProperty("Default", [System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::Instance)

我遇到错误

Multiple ambiguous overloads found for "GetProperty" and the argument count: "2".



如何消除歧义并指定我想要带字符串和BindingFlags的重载?

最佳答案

-bor运算符返回基础类型(本例中为[int])而不是原始枚举类型的结果。因此,您必须将结果转换回[System.Reflection.BindingFlags],尽管我更喜欢从字符串转换为枚举类型:

$propInfo = $type.GetProperty("Default", [System.Reflection.BindingFlags]'NonPublic, Instance')

关于powershell - 如何在Powershell中消除Type.GetProperty方法的歧义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30853378/

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