본문 바로가기

전체 글

(55)
C# json으로 변환할 때 유용한 타입 using System.IO; using System.Text.Json; dynamic obj = new System.Dynamic.ExpandoObject(); obj.hello = "안녕?"; obj.there = "난, 민이라고 해."; obj.初めまして = new[]{"よろしく","なのです。"}; var str =JsonSerializer.Serialize(obj); Console.WriteLine(str); {"hello":"\uC548\uB155?","there":"\uB09C, \uBBFC\uC774\uB77C\uACE0 \uD574.","\u521D\u3081\u307E\u3057\u3066":["\u3088\u308D\u3057\u304F","\u306A\u306E\u3067\u3059\..
C# 정적맴버 호이스팅? (서로를 참조하는) class Class1{ public static int a = b; public static int b = a; } Console.WriteLine(Class1.a); 위의 코드는 컴파일할 때 호이스팅?이 일어나서 오류가 나지 않는다. (다른 언어에서는 오류) 단 정적맴버가 아닌 멤버의 경우는 컴파일 오류.
C# ValueTuple 의 한계점. static IEnumerable Enum(this ValueTuple vt) => GetObjs(vt); static IEnumerable Enum(this ValueTuple vt) => GetObjs(vt); static IEnumerable Enum(this ValueTuple vt) => GetObjs(vt); static IEnumerable Enum(this ValueTuple vt) => GetObjs(vt); static IEnumerable Enum(this ValueTuple vt) => GetObjs(vt); static IEnumerable Enum(this ValueTuple vt) => GetObjs(vt); static IEnumerable Enum(this ValueTupl..
c# config 파일 경로 바꾸는 2가지 방법. 사전지식 그냥 내버려두면 debug 폴더 따로, release 폴더 따로 저장된다. 특정 위치에 하나만 두고 글로발 하게 사용하고 싶을 떄 2가지 방법이 있는 거 같다. 실습 1. var config = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap(){ExeConfigFilename = SomePath + "/App.config"}, ConfigurationUserLevel.None); 2. AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", SomePath + "/App.config"); var config = ConfigurationManager.OpenExeConfigu..
c# 자바스크립트 문자열 encode & decode (escape) 사전지식 C#코드로 웹페이지(html)에 자바스크립트 문자열을 박을 때에는 encoding을 해줘야 한다. 쌍따옴표나 홑따옴표 또는 탈출문자열이 섞여 있을 때 문제가 되기 떄문이다. (웹브라우저가 파싱을 못해요) 실습 public static object Escape(string str) { return HttpUtility.JavaScriptStringEncode(str); } public static string UnEscape(string str) { StringBuilder sb = new(str.Length); for (int i = 0; i i + 4) { ++i; int hex = Convert.ToInt32(str[i..(i+4)] , 16); sb.Append((char)hex); i+=..
c# 특정 폴더 컴파일 제외 .csproj 수정 사전지식 때때로 컴파일이 안됬으면 하는 cs파일이 있기 마련이다. 실습 .csproj 파일 Exe net6.0 10.0 설명 Views 폴더에 있는 cs파일은 컴파일 대상에서 제외된다.
c# 빌드할때 폴더 복사 .csproj 수정 사전지식 폴더에 내용물과 함께 전체복사. 실습 .csproj 파일 Exe net6.0 10.0 PreserveNewest 설명 위내용 처럼 itemGroup을 추가하여 빌드를 하면 public 폴더가 통째로 빌드 폴더에 복사 된다.
c# 프로젝트 폴더 경로 구하기. 사전지식 용량이 커지면 프로젝트 폴더에 있는 리소스에 접근하는게 낫다는 생각이든다. 빌드 폴더에 리소스를 복사해도 되지만 그것의 용량이 크면 부담스럽기 때문이다. 실습 public static readonly string projPath = new Func(() => { var projDir = Environment.CurrentDirectory; var m = Regex.Match(projDir, "[\\\\/]{1}bin[\\\\/]{1}(Debug|Relase)"); if (m.Success) projDir = projDir[0..m.Index]; return projDir; })();