MVVM 的 ReSharper 警告 [英] ReSharper warnings with MVVM

查看:52
本文介绍了MVVM 的 ReSharper 警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 WPF 实现 MVVM 模式时,我发现 ReSharper 经常警告我某些属性从未在我的 ViewModel 中使用过.问题是它们正在被使用,但只被数据绑定系统使用.有没有其他人遇到过这种烦恼,有没有办法帮助 ReSharper 意识到这些属性确实正在被使用?我很高兴,至少,VS 2010 正确地意识到 [Import] 标记的成员不会始终为空",但希望我也能解决这个问题.

As I implement the MVVM pattern with WPF, I'm finding that ReSharper is often warning me that certain properties are never used in my ViewModels. The problem is that they are being used, but only by the data binding system. Has anyone else encountered this annoyance and is there a way to help ReSharper realize that these properties are, indeed, being used? I am glad, at least, that VS 2010 properly realizes that [Import] tagged members won't "always be null", but hopefully I can fix this issue as well.

推荐答案

您可以使用外部注释向 ReSharper 指示使用了该方法,因此不会警告您.请在此处查看 ReSharper 文档.

You can use External Annotations to indicate to ReSharper the method is used and thus not to warn you. See the ReSharper docs on that here.

您需要使用 [UsedImplicitlyAttribute] 修饰任何此类方法.

You need to decorate any such methods with [UsedImplicitlyAttribute].

在使用该属性之前,您会看到:

Before using the attribute, you see:

然后,应用属性后:

[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
class NotUsed
{
    public int Field1 { get; set; }
    public int Field2 { get; set; }
}

这篇关于MVVM 的 ReSharper 警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆