다음을 통해 공유


괄호 기본 설정(IDE0047 및 IDE0048)

이 문서에서는 IDE0047IDE0048두 가지 관련 규칙을 설명합니다.

재산 가치
규칙 ID IDE0047
타이틀 불필요한 괄호 제거
범주 스타일
하위 범주 언어 규칙(괄호 기본 설정)
적용 가능한 언어 C# 및 Visual Basic
출시된 버전 Visual Studio 2017
옵션 dotnet_style_parentheses_in_arithmetic_binary_operators
dotnet_style_parentheses_in_relational_binary_operators
dotnet_style_parentheses_in_other_binary_operators
dotnet_style_parentheses_in_other_operators
재산 가치
규칙 ID IDE0048
제목 명확성을 위해 괄호 추가
범주 스타일
하위 범주 언어 규칙(괄호 기본 설정)
적용 가능한 언어 C# 및 Visual Basic
소개된 버전 Visual Studio 2017
옵션 dotnet_style_parentheses_in_arithmetic_binary_operators
dotnet_style_parentheses_in_relational_binary_operators
dotnet_style_parentheses_in_other_binary_operators
dotnet_style_parentheses_in_other_operators

개요

이 섹션의 스타일 규칙은 산술, 관계형 및 기타 이진 연산자우선 순위를 명확히 하기 위해 괄호를 사용하는 등 괄호 기본 설정과 관련이 있습니다.

옵션

이 규칙에는 연산자 유형에 따라 기본 설정을 지정하는 관련 옵션이 있습니다.

옵션 구성에 대한 자세한 내용은 옵션 형식참조하세요.

산술 이진 연산자에서 괄호 스타일_dotnet

재산 묘사
옵션 이름 dotnet_style_parentheses_in_arithmetic_binary_operators
옵션 값 always_for_clarity 산술 연산자 우선 순위를 명확히 하려면 괄호를 선호합니다.
never_if_unnecessary 산술 연산자 우선 순위가 명백한 경우 괄호를 사용하지 않는 것이 좋습니다.
기본 옵션 값 always_for_clarity

산술 이진 연산자는 *, /, %, +, -, <<, >>, &, ^|.

// dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity
var v = a + (b * c);

// dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary
var v = a + b * c;
' dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity
Dim v = a + (b * c)

' dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary
Dim v = a + b * c

dotnet_관계형_이진_연산자에서_괄호_스타일

재산 설명
옵션 이름 dotnet_style_parentheses_in_relational_binary_operators
옵션 값 always_for_clarity 관계형 연산자 우선 순위를 명확히 하려면 괄호를 사용하는 것이 좋습니다.
never_if_unnecessary 관계형 연산자 우선 순위가 명백한 경우 괄호를 사용하지 않는 것이 좋습니다.
기본 옵션 값 always_for_clarity

관계형 이진 연산자는 >, <, <=, >=, is, as, ==!=.

// dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity
var v = (a < b) == (c > d);

// dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary
var v = a < b == c > d;
' dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity
Dim v = (a < b) = (c > d)

' dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary
Dim v = a < b = c > d

다른 이항 연산자에서 괄호 사용 스타일 설정 (dotnet_style_parentheses_in_other_binary_operators)

재산 묘사
옵션 이름 dotnet_style_parentheses_in_other_binary_operators (다른 이항 연산자에서 괄호 사용 스타일)
옵션 값 always_for_clarity 다른 이진 연산자 우선 순위를 명확히 하려면 괄호를 사용하는 것이 좋습니다.
never_if_unnecessary 다른 이진 연산자 우선 순위가 명백한 경우 괄호를 사용하지 않는 것이 좋습니다.
기본 옵션 값 always_for_clarity

다른 이진 연산자는 &&, ||??.

// dotnet_style_parentheses_in_other_binary_operators = always_for_clarity
var v = a || (b && c);

// dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary
var v = a || b && c;
' dotnet_style_parentheses_in_other_binary_operators = always_for_clarity
Dim v = a OrElse (b AndAlso c)

' dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary
Dim v = a OrElse b AndAlso c

dotnet 스타일 연산자 안 괄호 사용 설정

재산 묘사
옵션 이름 dotnet_style_parentheses_in_other_operators (점 연산자 안에서는 괄호 사용 스타일)
옵션 값 always_for_clarity 다른 연산자 우선 순위를 명확히 하려면 괄호를 사용하는 것이 좋습니다.
never_if_unnecessary 다른 연산자 우선 순위가 명백한 경우 괄호를 사용하지 않는 것이 좋습니다.
기본 옵션 값 never_if_unnecessary

이 옵션은 이외의 연산자에 적용됩니다.

*, /, %, +, -, <<, >>, &, ^, |>, <, <=, >=, is, as, ==, !=&&, ||, ??

// dotnet_style_parentheses_in_other_operators = always_for_clarity
var v = (a.b).Length;

// dotnet_style_parentheses_in_other_operators = never_if_unnecessary
var v = a.b.Length;
' dotnet_style_parentheses_in_other_operators = always_for_clarity
Dim v = (a.b).Length

' dotnet_style_parentheses_in_other_operators = never_if_unnecessary
Dim v = a.b.Length

경고 표시 안 함

단일 위반만 표시하지 않으려면 소스 파일에 전처리기 지시문을 추가하여 규칙을 사용하지 않도록 설정한 다음 다시 사용하도록 설정합니다.

#pragma warning disable IDE0047 // Or IDE0048
// The code that's violating the rule is on this line.
#pragma warning restore IDE0047 // Or IDE0048

파일, 폴더 또는 프로젝트에 대한 규칙을 사용하지 않도록 설정하려면 해당 심각도를 구성 파일none 설정합니다.

[*.{cs,vb}]
dotnet_diagnostic.IDE0047.severity = none
dotnet_diagnostic.IDE0048.severity = none

모든 코드 스타일 규칙을 비활성화하려면 구성 파일에서 범주 Style에 대한 심각도를 none으로 설정합니다.

[*.{cs,vb}]
dotnet_analyzer_diagnostic.category-Style.severity = none

자세한 내용은 코드 분석 경고표시하지 않는 방법을 참조하세요.

참고 항목