WPF MVVM 平等

发布于 2024-08-09 06:42:37 字数 317 浏览 5 评论 0原文

我想在我正在开发的 WPF 项目中使用 MVVM,包括使用 RelayCommands(又名 DelegateCommands)。在为 ViewModel 实现平等时,我遇到了一个有趣但令人沮丧的问题,如此处所述。我的 ViewModel 层次结构中有一个基类,它反射性地检查所有属性,作为其相等比较的一部分,并且命令始终失败,即使它看起来不应该失败。

你们中的其他人如何使用这种设计方法来处理平等问题?

干杯,
贝里尔

I would like to use an MVVM in a WPF project I'm working on, including the use of RelayCommands (aka DelegateCommands). I'm running into an interesting but frustration problem in implementing equality for my ViewModels, outlined here. I have a base class in my ViewModel hierarchy which examines all properties reflectively as part of its equality comparison, and the Command consistently fails even when it looks like it shouldn't.

How are others of you using this design approach dealing with equality?

Cheers,
Berryl

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

溺渁∝ 2024-08-16 06:42:37

如果您要比较委托,特别是如果您使用 lambda 或匿名委托,它们的 RuntimeType 可能会有所不同。

我的建议是您在每种类型上手动重写这些类型的 Equals 方法。在进行这些基于反射的比较时,您可能会受到性能影响,并且您总是会遇到这些挑剔的小问题。

我知道这感觉像是你应该能够一次性解决的问题,但这似乎不太可能。我希望这不会让你的风帆变得太大。

If you are comparing delegates, it's likely that, especially if you use lambdas or anonymous delegates, that their RuntimeTypes are different.

My suggestion would be that you override the Equals method for these types manually on each type. You are likely taking a performance hit in doing these reflection-based comparisons and you are always going to run into these little nitpicky problems.

I know it feels like something you should be able to solve once and forever, but this doesn't seem likely. I hope this doesn't let the wind out of your sails too much.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文