在某些情况下禁用 IDE0002 规则?
Disable IDE0002 rule in some cases?
你能以某种方式微调 Visual Studio 2022 年的规则“简化成员访问 (IDE0002)”吗?它最有用,直到它不是:)
internal class Good_God_Please_Help_Why_Is_This_Class_Name_So_Looooooooooooooooooooooooooooooooooong {
internal class SomeConstants {
public const string A = "A";
public const string B = "B";
}
}
internal class Salvation : Good_God_Please_Help_Why_Is_This_Class_Name_So_Looooooooooooooooooooooooooooooooooong { }
internal class Test {
void SomeMethod() {
var a = Salvation.SomeConstants.A;
}
}
上面的代码产生以下简化:
使用SuppressMessage
:
using System.Diagnostics.CodeAnalysis;
internal class Test
{
[SuppressMessage("Style", "IDE0002")]
private void SomeMethod()
{
var a = Salvation.SomeConstants.A;
}
}
之前:
之后:
或者,导入静态成员:
using static Good_God_Please_Help_Why_Is_This_Class_Name_So_Looooooooooooooooooooooooooooooooooong;
internal class Test
{
private void SomeMethod()
{
var a = SomeConstants.A;
}
}
你能以某种方式微调 Visual Studio 2022 年的规则“简化成员访问 (IDE0002)”吗?它最有用,直到它不是:)
internal class Good_God_Please_Help_Why_Is_This_Class_Name_So_Looooooooooooooooooooooooooooooooooong {
internal class SomeConstants {
public const string A = "A";
public const string B = "B";
}
}
internal class Salvation : Good_God_Please_Help_Why_Is_This_Class_Name_So_Looooooooooooooooooooooooooooooooooong { }
internal class Test {
void SomeMethod() {
var a = Salvation.SomeConstants.A;
}
}
上面的代码产生以下简化:
使用SuppressMessage
:
using System.Diagnostics.CodeAnalysis;
internal class Test
{
[SuppressMessage("Style", "IDE0002")]
private void SomeMethod()
{
var a = Salvation.SomeConstants.A;
}
}
之前:
之后:
或者,导入静态成员:
using static Good_God_Please_Help_Why_Is_This_Class_Name_So_Looooooooooooooooooooooooooooooooooong;
internal class Test
{
private void SomeMethod()
{
var a = SomeConstants.A;
}
}