简体   繁体   English

c#,重构属性以访问表达式的私有字段 - 主体属性

[英]c#, refactor property to access private field to expression - bodied property

Given something like this给出这样的东西

public bool Hidden
{
    get => _hidden;
    private set => _hidden = value;
}

Or或者

public bool Hidden { get; private set; }

I would like to refactor the above so all set accessors of the Hidden property uses the _hidden field.我想重构上面的内容,以便 Hidden 属性的所有设置访问器都使用 _hidden 字段。 In other words the property should look like this afterwards:换句话说,该属性之后应该如下所示:

public bool Hidden => _hidden;

and all accessors in the class should assign a value to the field _hidden.并且 class 中的所有访问器都应该为字段 _hidden 赋值。

But I dont know how to do this using Resharper?但我不知道如何使用 Resharper 做到这一点?

There is no chance to do this ootb with ReSharper, that's too complex.没有机会使用 ReSharper 执行此 ootb,那太复杂了。 You'd have to write a custom plugin for that.您必须为此编写一个自定义插件。

JetBrains has this fantastic template which gets you started quite fast. JetBrains 有这个很棒的模板,可以让您快速入门。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM