Using 정렬
Visual Studio 사용자 인터페이스의 Using 정렬 옵션은 using 지시문, using 별칭 및 extern 별칭을 다음과 같은 순서에 따라 사전순으로 정렬하고 구성하여 소스 코드의 가독성을 향상시킵니다.
extern 별칭
using 지시문
using 별칭
[!참고]
기본적으로 Visual Studio에서 System으로 시작하는 using 지시문은 다른 using 지시문보다 앞에 정렬됩니다.Using 정렬을 수정하여 모든 using 지시문을 사전순으로 정렬할 수 있습니다.자세한 내용은 옵션, 텍스트 편집기, C#, 고급를 참조하십시오.
작업을 호출하는 두 가지 방법이 있습니다.
주 메뉴 - 편집 메뉴에서 IntelliSense, Using 구성을 차례로 가리킨 다음 Using 정렬을 클릭합니다.
상황에 맞는 메뉴 - 코드 편집기 안쪽을 마우스 오른쪽 단추로 클릭하고 Using 구성을 가리킨 다음 Using 정렬을 클릭합니다.
다음 예제에서는 소스 코드에서 수행 중인 Using 정렬의 결과를 보여 줍니다.
앞 |
뒤 |
---|---|
extern alias ApressLibrary2; extern alias ApressLibrary1; using aio = apressio; using System.Collections; using Microsoft.CSharp; using System; using apressio = Apress.IO; |
extern alias ApressLibrary1; extern alias ApressLibrary2; using System; using System.Collections; using Microsoft.CSharp; using aio = apressio; using apressio = Apress.IO; |
설명
전처리기 지시문
전처리기 지시문이 지시문 또는 별칭을 구분할 경우 Using 정렬은 정렬되지 않습니다.예를 들어 다음 코드는 정렬되지 않습니다.
// Not sorted because preprocessor directives separate the using directives.
using System.Linq;
#region MyRegion
using System.Collections.Generic;
using System;
#endregion
using System.Collections;
그러나 다음의 예제는 정렬됩니다.
// Sorted because pre-processor directives do not separate using directives
#region MyRegion
using System.Collections;
using System;
using System.Collections.Generic;
#endregion
설명
지시문 바로 위에 있거나 지시문과 같은 줄에 있는 주석은 지시문과 함께 정렬하는 동안 그룹화됩니다.다음 예제는 이 동작을 보여 줍니다.
앞 |
뒤 |
---|---|
// © Contoso, Ltd using apressdata = Apress.Data; using aio = apressio; using System.Collections; using System; // using System; using System.Collections.Generic; // using System.Text using System.Text; using apressio = Apress.IO; // The End |
using System; // using System; using System.Collections; using System.Collections.Generic; // using System.Text using System.Text; using aio = apressio; // © Contoso, Ltd using apressdata = Apress.Data; using apressio = Apress.IO; // The End |
위 예제에서 // © Contoso, Ltd 주석은 아래쪽의 using 문과 함께 그룹화 및 정렬됩니다. 이 문과 주석 사이에 캐리지 리턴이 없기 때문입니다.이러한 결과를 방지하려면 주석 다음에 캐리지 리턴을 추가해야 합니다.