본문 바로가기

Development/c#

(19)
반응형
[C#] 현재 설정 된 IP 가져오기 Win32_NetworkAdapterConfiguration 참조 https://docs.microsoft.com/ko-kr/windows/win32/cimwin32prov/win32-networkadapterconfiguration Win32_NetworkAdapterConfiguration 클래스 - Win32 apps 네트워크 어댑터의 특성 및 동작을 나타냅니다. 이 클래스는 네트워크 어댑터와 독립적인 TCP/IP 프로토콜의 관리를 지 원하는 추가 속성 및 메서드를 포함 합니다. docs.microsoft.com 개발 환경 : Visual Studio 2019 (c#) public void GetIP() { // System.Management.dll 추가 // using System.Managem..
[c#] query 를 StringBuilder 로 변환 하기 [TestMothod] public void QueryToStringBuilder() { string query = Clipboard.GetText(); // 클립보드에 저장된 쿼리를 가져옴 string[] list = query.Split(new string[] {"\r\n","\r","\n"}, StringSplitOptions.None); StringBuilder sb = new StringBuilder(); sb.AppendLine(" StringBuilder sb = new StringBuilder(); "); foreach (var item in lines) { sb.AppendLine(string.Format(" sb.AppendLine(\" {0} \"); ",item)); } Clipbo..
[C#] IPConfig 결과 값 받아오기 소스는 간단하다. /// /// IPconfig 결과를 String 반환 /// [TestMethod] public void GetIPConfig() { ProcessStartInfo psInfo = new ProcessStartInfo(); // 실행 파일 psInfo.FileName = @"c:\windows\system32\ipconfig.exe"; // 옵션 psInfo.Arguments = "/all"; // 윈도우를 열지 않늠 psInfo.CreateNoWindow = false; //쉘 기능을 사용하지 않음 psInfo.UseShellExecute = false; //표준 출력 리다이렉트 psInfo.RedirectStandardOutput = true; //실행 Process p = Pro..
[C#] 현재 실행하는 메소스 정보 확인 현재 실행하는 메소스 정보를 확인해 보도록 하겠다. using System.Reflection; public void GetMethodInfo() { Debug.WriteLine(string.Format("Class Full Name : {0}", MethodBase.GetCurrentMethod().ReflectedType.FullName)); Debug.WriteLine(string.Format("method Name : {0}", MethodBase.GetCurrentMethod().Name)); } /* 결과 Class Full Name : UnitTestProject.UnitTest1 method Name : GetMethodInfo */ MSDN MethodBase.GetCurrentMetho..
[C#] 경과 시간 확인 하기 Log 를 생성할 경우 메소드의 경과 시간이 필요 할 경우가 있다. 이번에는 경과 시간을 확인 해 보도록 하겠다. 구문은 다음과 같다. using System.Diagnostics; public void GetElapsedTime() { Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < 10; i++) { Thread.Sleep(1000); } Debug.WriteLine(string.Format("[경과시간] {0} Total Hours", sw.Elapsed.TotalHours.ToString())); Debug.WriteLine(string.Format("[경과시간] {0} Hours", sw.Elapsed.Hours.ToString(..
「C#」Clickonce 설치 시 "응용프로그램 설치 - 보안 경로" 로 인해 설치가 안될때 환경 : Visual Stuido 2015 이때는 당황하지 말고 메뉴 > regedit 경로 : \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\Security\TrustManager\PromptingLevel 설치가 가능해 졌습니다.
[c#] DateTime 차이 계산 환경 : Visual Studio 2015 DateTime 차이 (시작 일시 ~ 종료 일시) 의 계산 public void DiffTime() { string format = "yyyyMMddHHmmss.fff"; string strStartDateTime = "19771001080000.000"; DateTime startDateTime = DateTime.ParseExact(strStartDateTime, format, CultureInfo.InvariantCulture); DateTime endDateTime = DateTime.Now; TimeSpan tsDiff = endDateTime - startDateTime; DateTime diffDateTime = DateTime.MinValue + ..
「c#」Microsoft.CSharp.RuntimeBinder.CSharpArugmentIfo.Create 멤버가 필요한 컴파일러가 없습니다 . 오류 환경 : Visual Studio 2015 Unit Test 프로젝트에서 단위 테스트 Class를 만들어 컴파일중 위와 같은 오류가 발생했다. ㅡ.ㅡ 검색해 보니 다음과 같이 간다하게 해결 된다.
[C#] 키보드 후킹시 키보드 키값 enum 환경 : Visual Studio 2015 키보드 후킹시 키보드 키값ㅇ을 사용하는데 찾기가 불편해서 등록 해 보았다. public enum VKeys : int { VK_LBUTTON = 0x01, //Left mouse button VK_RBUTTON = 0x02, //Right mouse button VK_CANCEL = 0x03, //Control-break processing VK_MBUTTON = 0x04, //Middle mouse button (three-button mouse) VK_BACK = 0x08, //BACKSPACE key VK_TAB = 0x09, //TAB key VK_CLEAR = 0x0C, //CLEAR key VK_RETURN = 0x0D, //ENTER key VK_S..
[C#] Json Text 를 Json Format 으로 변경 역시 우리의 구글님은 날 실망 시키지 않으신다. ㅎㅎ 아래의 Method를 이용해서 json을 string으로 주면 Formatting 되어 반환 해 준다. public string ChageJsonStringToJsonFomat(string json) { int indentation = 0; int quoteCount = 0; var result = from ch in json let quotes = ch == '"' ? quoteCount++ : quoteCount let lineBreak = ch == ',' && quotes % 2 == 0 ? ch + Environment.NewLine + String.Concat(Enumerable.Repeat(INDENT_STRING, indentation)..