Microsoft MVP성태의 닷넷 이야기
.NET Framework: 253. Roslyn 맛보기 - C# Interactive (1) [링크 복사], [링크+제목 복사],
조회: 33045
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 7개 있습니다.)

Roslyn 맛보기 - C# Interactive (1)


Roslyn 맛보기 (1) - C# 소스 코드를 스크립트 처럼 다루는 방법
Roslyn 맛보기 (2) - C# Interactive (1)
Roslyn 맛보기 (3) - C# Interactive (2)
Roslyn 맛보기 (4) - Roslyn Services APIs를 이용한 Code Issue 및 Code Action 기능 소개
Roslyn 맛보기 (5) - Syntax Analysis (Roslyn Syntax API)
Roslyn 맛보기 (6) - Roslyn Symbol / Binding API
Roslyn 맛보기 (7) - SyntaxTree 조작

F# 공부하시는 분들은... "F# Interactive" 윈도우를 한번쯤 사용해 보셨을 텐데요. Roslyn이 나오면서, Roslyn 자체의 실습(?) 대상으로 만들어져 제공되는 "C# Interactive"가 새롭게 추가되었습니다. (아니면, C# 용 "Immediate Window"가 하나 생겼다고 보셔도 됩니다. ^^)

Roslyn을 설치하면, Visual Studio에서 "View" / "Other Windows" / "C# Interactive Window" 메뉴가 생기는데, 실행하면 다음과 같은 창이 뜹니다.

csharp_interactive_1.png

여기에 입력할 수 있는 명령어는 크게 2가지 종류로 나뉩니다.

  • C# Interactive 명령어
  • C# 코드

"C# Interactive"의 자체적인 명령어는 prompt에서 "# (Sharp)" 글자로 시작해서 명령을 내리면 됩니다. 아래는 '#help'로 구한 명령어 목록입니다.

cls Clears the contents of the REPL editor window.
help Display help on specified command, or all available commands and key bindings if none specified.
load Executes the specified file within the current interactive session.
prompt Changes the current prompt settings.
reset Reset the execution environment to the initial state, keep REPL history.


그 외에 입력되는 모든 문자열은 "C# 코드"라고 보시면 됩니다. Interactive 창에서 수행되는 모든 C# 명령어는 하나의 문맥을 공유합니다. 지난번 글에서 살펴본 대로라면,

Roslyn 맛보기 - C# 소스 코드를 스크립트 처럼 다루는 방법
; https://www.sysnet.pe.kr/2/0/1153

단일 Session 값이 유지된다는 의미가 됩니다. 일련의 명령어들이 같은 Session 인스턴스를 공유하기 때문에 아래의 화면에서처럼 이전 명령어 실행 결과에 영향을 받는 실행 결과를 보여줍니다.

csharp_interactive_2.png




처음에는, C# Interactive 기능이 F#에 비해서 과연 많이 쓰일까 하는 의문이 들었는데, 경험상 나름 개발을 하는 동안 간단한 코드들에 대한 검증에서 유용하게 사용할 수 있었습니다. 예를 들어, "닷넷에서 지원되는 문자열 인코딩 이름 목록" 글에서 보여지는 간단한 코드들의 경우에 기존에는 일부러 테스트를 위해 콘솔 프로젝트를 별도로 만들어서 확인해야 했는데, 이제는 빠르게 C# Interactive 윈도우에서 그 결과를 확인할 수 있었습니다.

사용하다보니, 기왕이면 #help 명령어로 나오는 단축키를 익혀두는 것이 좋겠더군요. ^^ (아래의 목록에서 '빨간색' 항목은 제가 자주 사용하는 단축키입니다.)

> #help
Keyboard shortcuts:
  Enter                Evaluate the current input if it appears to be complete.
  Ctrl-Enter           If the caret is in current pending input submission, evaluate the entire submission.
                       If the caret is in a previous input block, copy that input text to the end of the buffer.
  Shift-Enter          If the caret is in the current pending input submission, insert a new line.
  Escape               If the caret is in the current pending input submission, delete the entire submission.
  Alt-UpArrow          Paste previous input at end of buffer, rotate through history.
  Alt-DownArrow        Paste next input at end of buffer, rotate through history.
  UpArrow              Normal editor buffer navigation.
  DownArrow            Normal editor buffer navigation.
  Ctrl-K, Ctrl-Enter   Paste the selection at the end of interactive buffer, leave caret at the end of input.
  Ctrl-E, Ctrl-Enter   Paste and execute the selection before any pending input in the interactive buffer.
  Ctrl-A               Alternatively select current input or whole buffer.

특히, Interactive 윈도우에서 직접 코드를 입력하기 보다는 C# 코드 윈도우 창에서 입력한 후 특정 영역을 선택하여 실행하는 "Ctrl-E, Ctrl-Enter"기능이 유용했습니다. (아쉽게도 F# Interactive에서 해당 기능의 단축키를 "Alt+Enter"로 선점하고 있어서 C#의 경우에 남은 단축키 영역이 부족해 어쩔 수 없이 복잡해진 것 같습니다. ^^)

참고로, 이번 글은 "C:\Program Files (x86)\Microsoft Codename Roslyn CTP\Documentation\Interactive - Executing Code in the Interactive Window.docx" 문서를 요약했다고 보시면 됩니다. ^^




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 6/27/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 151  152  153  154  155  156  157  158  [159]  160  161  162  163  164  165  ...
NoWriterDateCnt.TitleFile(s)
1068정성태6/16/201125316개발 환경 구성: 127. Portable Library - 닷넷 N-Screen용 공통 라이브러리 제작 [1]
1067정성태6/15/201124885오류 유형: 126. Windows failed to apply the Group Policy Folder Options settings. [1]
1066정성태6/14/201127872개발 환경 구성: 126. MSDN 구독자 - Windows Azure 무료 서비스 신청하는 방법 [4]
1065정성태6/13/201132675개발 환경 구성: 125. Firebird - 유니코드 기본 문자셋 지정
1064정성태6/11/201127328웹: 22. Visual Studio 2010에서 CSS 3 인텔리센스(intellisense) 지원하는 방법 [1]
1063정성태6/10/201128940웹: 21. Sysnet 웹 사이트의 CSS 2.1 변환 기록 [1]
1062정성태6/9/201129135웹: 20. Sysnet 웹 사이트의 HTML5 변환 기록 [1]
1061정성태6/8/201127365오류 유형: 125. 인터넷 익스플로러 - 개발자 도구에서 정지점(BP: Breakpoint) 설정이 안 되는 경우 [1]
1060정성태6/8/201123917VC++: 51. PHP 모듈의 F5 디버깅
1059정성태6/6/201129064VC++: 50. PHP 모듈 - php_mysql 빌드하는 방법파일 다운로드1
1058정성태6/5/201132680개발 환경 구성: 124. .NET 개발자가 처음 해보는 PHP + MySQL 연동 [2]
1057정성태6/4/201130033VC++: 49. 소스 코드로부터 php5apache2_2.dll 생성하는 방법파일 다운로드1
1056정성태6/2/201128191VC++: 48. 윈도우에서 Apache Module - Content Handler 컴파일파일 다운로드1
1055정성태6/1/201125435오류 유형: 124. MVC 프로젝트의 Site.Master 관련 오류 정리
1054정성태5/31/201129660.NET Framework: 220. ASP.NET MVC Web Site 프로젝트 - 단위 테스트 작성파일 다운로드1
1053정성태5/31/201132210VC++: 47. Apache Module에 대한 'F5 디버그 (Start with debugging)' [2]
1052정성태5/30/201129843.NET Framework: 219. ASP.NET MVC Web Site 프로젝트 구성하기파일 다운로드1
1051정성태5/28/201138333VC++: 46. 윈도우에서 Apache Module 컴파일 (VC++)파일 다운로드1
1050정성태5/28/201124517오류 유형: 123. Firebird - Exception of type 'FirebirdSql.Data.Common.IscException' was thrown.
1049정성태5/28/201130216.NET Framework: 218. WCF REST 서비스 - 웹 브라우저 측 Ajax 호출 캐시 [1]
1048정성태5/27/201132127개발 환경 구성: 123. Apache 소스를 윈도우 환경에서 빌드하기
1047정성태5/27/201126013.NET Framework: 217. Firebird ALinq Provider - 날짜 필드에 대한 낙관적 동시성 쿼리 오류
1046정성태5/26/201130653.NET Framework: 216. 라이선스까지도 뛰어넘는 .NET Profiler [5]
1045정성태5/24/201131718.NET Framework: 215. 닷넷 System.ComponentModel.LicenseManager를 이용한 라이선스 적용 [1]파일 다운로드1
1044정성태5/24/201132276오류 유형: 122. zlib 빌드 오류 - inflate.obj : error LNK2001: unresolved external symbol _inflate_fast
1043정성태5/24/201131236.NET Framework: 214. 무료 Linq Provider - DbLinq를 이용한 Firebird 접근파일 다운로드1
... 151  152  153  154  155  156  157  158  [159]  160  161  162  163  164  165  ...