본문 바로가기

프로그래밍/C#33

Dapper 사용시 key/explicitKey Dapper를 사용할 때 insert시 pk를 자동으로 채워주려면 해당 변수를 [Key] 로 해줘야함 ex) public class ItemEntity { [Key] public long ItemIdx {get;set;} public long InsertToDB() { conn.Insert(this); return ItemIdx; } } - explicitKey키로 어트리뷰트를 하면 위의 방법은 적용되지 않음 [추가 + ] [key] : "데이터베이스에서 자동으로 생성되는 키로 속성 지정"으로 정의 ( Auto Increment) [Explicti Key] : 키는 키인데 자동 증가 하지 않는 컬럼 https://stackoverflow.com/questions/49428967/dappers-explic.. 2020. 1. 3.
GetLocalIP() - 본인 pc localIP 받는 코드. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 string GetLocalIP() { string result = string.Empty; var host = Dns.GetHostEntry(Dns.GetHostName()); foreach (var ip in host.AddressList) { if (ip.AddressFamily == AddressFamily.InterNetwork) { result = ip.ToString(); break; } } return result; } er 2019. 11. 13.
Reflection : 객체 이름으로 객체 생성하기. Main 함수 using System; using System.Collections.Generic; namespace Study { class Program { static void Main(string[] args) { // IAnimal 리스트 var list = new List(); // type.GetType 으로 Cat 객체 생성 var animal = Type.GetType("Study.Cat"); var cat = Activator.CreateInstance(animal) as Cat; cat.Name = "고양이"; list.Add(cat); // type.GetType 으로 Dog 객체 생성 animal = Type.GetType("Study.Dog"); var dog = Activato.. 2019. 7. 29.
WCF 로그인 서버 공부 및 만들기 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 12.. 2019. 6. 3.
Wcf : binding 바인딩은 엔드포인트에연결하는 데 필요한 전송, 인코딩 및 프로토콜을 지정합니다. 바인딩 확장명 및 사용자 지정 바인딩은 응용 프로그램 기능을 지원하는데 필요한 사용자 통신 기능을 구현합니다. 출처 : https://docs.microsoft.com/ko-kr/dotnet/framework/wcf/extending/extending-bindings 2019. 5. 26.
string , string builder 차이 using System;using System.Collections.Generic;using System.Diagnostics;using System.Linq;using System.Text;using System.Threading;using System.Threading.Tasks;namespace study{ class Program { static void Main(string[] args) { string txt = "helloworld "; StringBuilder sb = new StringBuilder(); sb.Append(txt); Stopwatch st = new Stopwatch(); st.Start(); for (int i = 0; i 2019. 3. 5.
[c#] Mutex , semaphore, monitor * Mutex 1. 설명- Mutex 클래스는 해당 머신의 프로세스간에서도 베타적Locking을 하는데 사용.- Mutex 락킹은 Monitor 락킹보다 약 50배 정도 느리기 때문에 프로세스내에서만 배타적 Lock이 필요한 경우 C#의 lock이나 Monitor클래스를 사용한다.- 한 프로세스 내에서 사용할 경우 Monitor를 사용하는 것이 빠른 방식이다. 2. Mutex 활용 - 한 머신내에서 오직 한 응용프로그램만 실행되도록 할 때 한 컴퓨터 내 한 프로세스만 뜨게 하기 위해 고유의 Mutex명을 지정할 필요가 있음. 처음 프로세스가 먼저 Mutex를 획득하면 다른 프로세스는 Mutex를 획득 할 수 없기 때문에 오직 하나의 프로그램만 머신내에서 실행되는 것 * Semaphore 1. 설명- 공유.. 2019. 2. 17.
[c#] local ip 찾는 함수 private string GetLocalIP() { string myIP = string.Empty; IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName()); foreach (var ip in host.AddressList) { if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { myIP = ip.ToString(); return myIP; } } return myIP; } 2018. 7. 3.
리플렉션 닷넷 응용프로그램의 어셈블리 파일에는 메타데이터가 들어있다.BCL에서 제공되는 리플렉션 관련 클래스를 이용하면 메타데이터 정보를 얻는 것이 가능하므로 이제 그 유용성을 직접 코드로 확인해 보자. 리플렉션은 C#코드가 빌드되어 어셈블리에 포함되는 경우 그에 대한 모든 정보를 조회할 수 있는 기술을 일컫는다. using System;using System.Threading;using System.Collections.Generic;using static System.Net.Mime.MediaTypeNames;using System.Reflection;namespace csharp_study{ class Program { static void Main(string[] args) { AppDomain curre.. 2017. 8. 13.
반응형