최근에는 asp.net core 에 한정해서 개발을 하다보니 대부분 Disable 하고 필요한 것만 Enable 해서 사용
사용중 .NET Core Add Reference .NET Core Test Explorer .NET Install Tool for Extension Authors ASP.NET Core Switcher Auto Close Tag Auto Rename Tag Auto-Using for C# Bookmarks C# C# Namespace Autocompletion Code Spell Checker CSS Flexbox Cheatsheet CSS […]
출처 : https://qiita.com/mkuwan/items/be6745f2c9e7823f8a66
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
public static class TypeExtention
{
/// <summary>
/// enumの値リストを取得
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static List < T > GetEnumList < T > ( this Type type ) where T : Enum
{
return Enum . GetValues ( typeof ( T ) ) . Cast < T > ( ) . ToList ( ) ;
}
/// <summary>
/// enumのDescripntionリストを取得
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static IEnumerable < string > GetEnumDescriptionEnumerable < T > ( this Type type ) where T : Enum
{
foreach ( T value in Enum . GetValues ( typeof ( T ) ) )
yield return value . GetDescriptionFromValue ( ) ;
}
/// <summary>
/// enumのDescripntionリストを取得
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static List < string > GetEnumDescriptionList < T > ( this Type type ) where T : Enum
{
List < string > descriptionList = new List < string > ( ) ;
foreach ( T value in Enum . GetValues ( typeof ( T ) ) )
descriptionList . Add ( value . GetDescriptionFromValue ( ) ) ;
return descriptionList ;
}
}
사용예
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
public enum SampleEnum
{
[ Description ( "東京" ) ]
Tokyo = 1 ,
[ Description ( "名古屋" ) ]
Nagoya = 3 ,
[ Description ( "札幌" ) ]
Sapporo = 5 ,
[ Description ( "大阪" ) ]
Osaka = 7
}
static void Test2 ( )
{
Console . WriteLine ( "EnumExtention GetDescriptionFromValueを使ってTokyoのDescriptionを取得" ) ;
Console . WriteLine ( SampleEnum . Tokyo . GetDescriptionFromValue ( ) ) ;
Console . WriteLine ( ) ;
Console . WriteLine ( "StringExtention GetEnumValueFromDescriptionを使ってDescriptionからenum値を取得" ) ;
Console . WriteLine ( "名古屋" . GetEnumValueFromDescription < SampleEnum > ( ) ) ;
Console . WriteLine ( ) ;
Console . WriteLine ( "IntExtention GetEnumDescriptionFromIntを使ってint値からDescriptionを取得" ) ;
var sapporo = ( ( int ) 5 ) . GetEnumDescriptionFromInt < SampleEnum > ( ) ;
Console . WriteLine ( sapporo ) ;
Console . WriteLine ( ) ;
Console . WriteLine ( "IntExtention GetEnumValueFromIntを使ってint値からenum値を取得" ) ;
var osaka = ( ( int ) 7 ) . GetEnumValueFromInt < SampleEnum > ( ) ;
Console . WriteLine ( osaka ) ;
Console . WriteLine ( ) ;
Console . WriteLine ( "TypeExtention GetEnumListを使ってenumの値リストを取得" ) ;
var enumValues = typeof ( SampleEnum ) . GetEnumList < SampleEnum > ( ) ;
foreach ( var e in enumValues )
Console . WriteLine ( e ) ;
Console . WriteLine ( ) ;
Console . WriteLine ( "TypeExtention GetEnumDescriptionListを使ってDescriptionリストを取得" ) ;
var enumDescriptions = typeof ( SampleEnum ) . GetEnumDescriptionList < SampleEnum > ( ) ;
foreach ( var e in enumDescriptions )
Console . WriteLine ( e ) ;
Console . WriteLine ( ) ;
Console . WriteLine ( "TypeExtention GetEnumDescriptionEnumerableを使ってDescriptionリストを取得" ) ;
var enumDescriptionsEnumerable = typeof ( SampleEnum ) . GetEnumDescriptionEnumerable < SampleEnum > ( ) ;
foreach ( var e in enumDescriptionsEnumerable )
Console . WriteLine ( e ) ;
Console . ReadLine ( ) ;
}
※ 참고 (2026년 기준) Microsoft.AspNetCore.Mvc.Versioning 패키지는 더 이상 업데이트되지 않고 Asp.Versioning.Mvc(Asp.Versioning.Http) 로 이름이 바뀌었다.
출처 : https://dotnetcoretutorials.com/2017/01/17/api-versioning-asp-net-core/
Install - Package Microsoft . AspNetCore . Mvc . Versioning
startup.cs
public void ConfigureServices ( IServiceCollection services )
{
// ApiVersioning을 추가
services . AddApiVersioning ( options = >
{
// 클라이언트에 Api 버전을 통지
options . ReportApiVersions = true ;
// 이것이 없으면 클라이언트 측에서 에러가 나온다
options . AssumeDefaultVersionWhenUnspecified = true ;
// Api의 default 버전을 1.0으로 설정
options . DefaultApiVersion = new ApiVersion ( 1 , 0 ) ;
} ) ;
}
출처에 보면 여러가지 방식(Url Query Based Versioning, URL Path Based Versioning, Http Header Based Versioning) 등이 있으나…
역시 익숙한 방식은
[ ApiVersion ( "1.0" ) ]
[ Route ( "api/{version:apiVersion}/home" ) ]
public class HomeV1Controller : Controller
{
[ HttpGet ]
public string Get ( ) = > "v1" ;
}
[ ApiVersion ( "2.0" ) ]
[ Route ( "api/{version:apiVersion}/home" ) ]
public class HomeV2Controller : Controller
{
[ HttpGet ]
public string Get ( ) = > "v2" ;
}
혹은
[ ApiVersion ( "1.0" ) ]
[ ApiVersion ( "2.0" ) ]
[ Route ( "v{version:apiVersion}/[controller]" ) ]
public class HomeController : Controller
{
[ HttpGet ]
public string Get ( ) = > "v1" ;
// Api 버전을 덮어 쓰기
[ HttpGet , MapToApiVersion ( "2.0" ) ]
public string GetV2 ( ) = > "v2" ;
}
/v1/Home, /v2/Home 의 형식으로 call 가능함
[…]
링크