gpt4 book ai didi

c# - 编码的 UI 测试向下转换不起作用

转载 作者:太空狗 更新时间:2023-10-29 23:51:57 25 4
gpt4 key购买 nike

我一直在尝试将泛型引入我们的自动化代码,因此我尝试将 WpfControl 转换为泛型类型 T,其中 T 被限制为 WpfControl 类型。

return control as T;

T 将始终是 WpfControl 的子对象,但是当我将类型为 WpfControl 的控件转换为泛型类型时,它返回 null。我还尝试将控制权强制转换为确切的子类型,例如:

var childControl = control as WpfTabList;

这仍然返回 null。有人遇到过类似的问题吗?

查看此 WpfControl Class

最佳答案

一些建议:

首先,在您的泛型方法中请使用 geteric 类型规范。喜欢

public T GetControl<T>(...) where T : WpfControl

你的假设和实现有误 您正在尝试将 WpfControlWpfTabList 匹配,这在子控件不是 TabList 的情况下是错误的。

关于c# - 编码的 UI 测试向下转换不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13741999/

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