Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagec#
themeEmacs
title개선된 패턴매칭예-if문 단계를 줄일수있음
linenumberstrue
switch (message)
{
    case Cmd cmd:        
        break;
    case "snap":       
        break;
    case "print":        
        break;
}


switch (shape)
{
    case Square s when s.Side == 0:
    case Circle c when c.Radius == 0:
        return 0;

    case Square s:
        return s.Side * s.Side;
    case Circle c:
        return c.Radius * c.Radius * Math.PI;
    default:
        throw new ArgumentException(
            message: "shape is not a recognized shape",
            paramName: nameof(shape));
}

...


컴파일러및 코드 분석기 프로젝트내에서 업그레이드

Info
nuget install Microsoft.Net.Compilers

...

   # Install C# and VB compilers
nuget install Microsoft.CodeAnalysis    # Install Language APIs and Services
참고 : https://github.com/dotnet/roslyn/tree/master

NetCompilers는 이전 Framework혹은 이전 VisualStudio에게 최신 C# 언어문법을 버젼을 제공합니다.

link: https://docs.microsoft.com/en-us/dotnet/csharp/pattern-matching

닷넷 버젼 4.5.2  과 Compiler Version 2.3.1 조합이 코드 인텔리젼과 빌드에서 문제가 없어보입니다. ( vs 2015기준. 2017.09테스트 기준)

그래도 종종 빌드는 잘되는데, 인텔리젼에서 오류를 표시할때도 있습니다. 


패턴매칭은 Scala에서 훨씬이전 도입된것인데 

...