本帖最后由 小白龙 于 2025-3-22 05:46 编辑
回复 8# Five66
多谢大佬指导, 确实是哪个问题,
我是想把下面链接的c#函数改为powershell
https://github.com/FlaUI/FlaUI/b ... ilityMethods.cs#L67
现在的问题是, 下面这行C#代码怎样正确改为powershell, 得先把上游问题解决掉var modalWindows = Retry.WhileEmpty(() => window.ModalWindows, TimeSpan.FromSeconds(1)).Result;COPY 下面代码是gpt生成的powershell, 改的不正确 | function CloseWindowWithDontSave { | | param($window) | | | | $window.Close() | | [Wait]::UntilInputIsProcessed() | | | | | | $modalWindows = [Retry]::WhileEmpty({$window.ModalWindows}, [TimeSpan]::FromSeconds(5)).Result | | | | | | if ([Tools.OperatingSystem]::IsWindows11()) { | | $dontSaveButton = $modalWindows[0].FindFirstDescendant("SecondaryButton").AsButton() | | } else { | | $dontSaveButton = $modalWindows[0].FindFirstDescendant( { param($cf) $cf.ByAutomationId("CommandButton_7")} ).AsButton() | | } | | | | | | $dontSaveButton.Invoke() | | }COPY |
原C#代码如下: | public static void CloseWindowWithDontSave(Window window) | | { | | window.Close(); | | Wait.UntilInputIsProcessed(); | | var modalWindows = Retry.WhileEmpty(() => window.ModalWindows, TimeSpan.FromSeconds(1)).Result; | | Button dontSaveButton; | | if (Tools.OperatingSystem.IsWindows11()) | | { | | dontSaveButton = modalWindows[0].FindFirstDescendant("SecondaryButton").AsButton(); | | } | | else | | { | | dontSaveButton = modalWindows[0].FindFirstDescendant(cf => cf.ByAutomationId("CommandButton_7")).AsButton(); | | } | | dontSaveButton.Invoke(); | | }COPY |
|