9월, 2013의 게시물 표시

Converting between types.

Casting Using the as operator Parsing. 문자열을 원하는 타입으로. Using System.Convert Using System.BitConverter. byte스트림을 원하는 값으로. Casting value type reference type Narrowing conversion 데이타 손실이 있을 수 있는 경우 is/as 사용해서 확인 후 Widening conversion 데이타 손실이 없는 있는 경우 상위 클래스로

CLR 관점에서는, Method의 Signature는 Method의 이름, Parameters로 구성된다. Return type은 아니다.

난 무식하다. ㅠㅠ

C# and Jon Skeet

너가 C#을 하는데, Jon Skeet을 모른다면 뭔가 문제가 있다. http://meta.stackoverflow.com/questions/1832/what-happens-when-jon-skeets-reputation-exceeds-the-limit-for-the-data-type-hol https://www.google.co.kr/search?q=jon+skeet+wiki&oq=Jon+Skeet&aqs=chrome.1.69i57j0j69i60j0l2.5194j0&sourceid=chrome&ie=UTF-8#newwindow=1&q=jon+skeet+chuck+norris http://codesqueeze.com/the-ultimate-top-25-chuck-norris-the-programmer-jokes/

현재 MS의 인증 프로그램(Certification program)

Solutions Associate level Designed to be the foundation for certifications in Microsoft proving technical skills. Solutions Expert level Expands on the knowledge of those at the Associate level and requires more rigor in the exams and knowledge tested. Candidates at this level should be able to build solutions using multiple technologies including cloud computing. Solutions Master level The top of the Microsoft certification program. Consists of certifications that require knowledge-based exams along with performance-based testing. Those who hold a Masters certification demand higher salaries.

.NET에서 제공되는 기본 Serialization 방법

XmlSerializer DataContractSerializer BinaryFormatter

LINQ to XML. 읽는 것은 모르겠는데, 쓰는 것은 확실히 편해보인다.

XML을 만들 때, XmlDocument 보단 더 편하다. var root = new XElement("Root", new List { new XElement("Child1"), new XElement("Child2"), new XElement("Child3") }, new XAttribute("Attr1", 10000), new XAttribute("Attr2", 20000), new XAttribute("Attr3", 30000)); root.Save("test.xml");

The Standard query operators.

All, Any, Average, Cast, Count, Distinct, GroupBy, Join, Max, Min, OrderBy, OrderByDescending, Select, SelectMany, Skip, SkipWhile, Sum, Take, TakeWhile, ThenBy, ThenByDescending, and Where. 그러하다.

XML in the .NET Framework

XmlReader A fast way of reading an XML file. You can move forward only through the file, and nothing is cached XmlWriter A fast way to create an XML file. Just as with the XmlReader, it’s forward only and noncached. XmlDocument Represents an in-memory XML document. It supports navigating and editing a document. XPathNavigator Helps with navigating through an XML document to find specific information. more  혹은  LINQ to XML

System.Transactions.TransactionScope 가 분산(Distributed) 트랜잭션도 처리할 수 있음.

로컬 트랜잭션만 자동으로 처리하는지 알았는데, 커넥션 객체가 두 개 이상 생기면, 분산 트랜잭션으로 바뀐다네. http://msdn.microsoft.com/en-us/library/ff649002.aspx http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope(v=vs.100).aspx

미처 몰랐던 System.IO.Path의 유용한 메서드

GetDirectoryName GetExtensions GetFileName GetPathRoot GetRandomFileName GetTempPath GetTempFileName http://msdn.microsoft.com/en-us/library/System.IO.Path(v=vs.100).aspx

Diagnostics in application.

Logging and Tracing Profiling application with StopWatch or Performance wizard Monitoring Performance Counters 아는 것이 많아질수록 어렵구나. ㅠㅠ

.PDB 파일

PDB 파일은 다음의 정보를 담고 있다. 소스 파일 이름과 줄번호 로컬 변수 이름 위의 두 정보는 디버깅시에 필요하다. 그리고 어셈블리 빌드시에 함께 만들어진 PDB 파일은 "Microsoft Symbol Server" 를 통해 디버거에게 보내질 수 있다. 단 이때 PDB파일에 담겨있는 Private 정보를 제거하려면 PDBCopy라는 프로그램을 이용해야 한다.

어셈블리를 바인딩하는 과정에 필요한 설정 파일

Publisher policy files : GAC Application configuration files  Machine configuration files 기타 주의사항 참조할 Private 어셈블리는 기본적으로 현재 실행 폴더나 하위 폴더에 있어야 한다. private 어셈블리의 위치는 "probing" 요소에서 상대 경로로 정할 수 있다. App.config 파일에 "codebase" 요소에서 지정된 위치에서 Public 어셈블리만 가져올 수 있다.

SecureString. 문자열을 해킹으로부터 지키자.

System.Security.SecureString 덤프나 페이지 파일을 통해서 원치 않는 문자열 정보가 유출될 수 있다. public static void ConvertToUnsecureString(SecureString securePassword) { IntPtr unmanagedString = IntPtr.Zero; try { unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(securePassword); Console.WriteLine(Marshal.PtrToStringUni(unmanagedString)); } finally { Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString); } }

Hashing is the process of taking a large set of data and mapping it to a smaller data set of fixed length.

그러하다. 참 깔끔한 정의다.

자주 쓰이는 정규식 패턴 검색. http://regexlib.com/

http://regexlib.com/ 굿~

Format 문자열의 정확한 문법. 차지하는 글자수를 정할 수 있는 옵션이 있는 줄은 미처 몰랐다.

A format item has the following syntax: { index [ , alignment ][  :   formatString ]  } Brackets denote optional elements. The opening and closing brackets are required. A format item has the following elements: index The zero-based index of the argument whose string representation is to be included at this position in the string. If the argument is  null , an empty string is included at this position in the string. alignment A signed integer that indicates the total length of the field into which the argument is inserted and whether it is right-aligned (a positive integer) or left-aligned (a negative integer). If  alignment  is omitted, the string representation of the corresponding argument is inserted in a field with no leading or trailing spaces. formatString A format string that specifies the format of the corresponding argument's result string. If  formatString  is omitted, the corresponding argument's parameterless  ToS...

MSDN 한글판의 문제점.

이제까지는 영문판만 봐서 미처 몰랐는데, 한글판은 번역이 안 된 경우만 있는 것이 아니고, 아예 일부 내용이 누락된 경우도 있나 보네. String.Format에 대한  영문판    한글판 Remark 섹션이 통채로 날아갔다. 헐... 아무리 생각해도 영어, 최소한 독해가 안 되면 개발자로 살아가기는 어려울 듯.

문자열 다룰 때 Globalization 고려해야 한다면 아래의 사항을 조심.

Make sure that all string comparisons use an explicit overload that takes a StringComparison object.  Use StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase when comparing strings in a culture-agnostic way. Use StringComparison.CurrentCulture when displaying text to the user. Make sure that all persisted text is persisted with the invariant culture. Make sure that you are not using String.Compareor CompareTofor equality testing. Implement IFormattablefor custom types that are displayed to the user to make sure that all culture settings are respected. Use the correct format strings when displaying numbers, dates, and times to the user. 

.NET에서 Excel 파일 읽기. 특히 구버전(97-2003)의 포맷일 경우.

NPOI  라이브러리 이용. Thanks to 안홍조 & 정세일 . CSV 포맷으로 올려서 읽는다. ODBC 드라이버를 설치해서 읽는다.  ODBC 연결 문자열 2003 이전 구포맷일 경우 상용컴포넌트 사용 ExpertXLS Excel Library for .NET ComponentOne 2007 이후 버전(Open XML Format) 일 경우 EPPlus , ClosedXml ,  NPOI  등등 매우 많은 오픈소스 프로젝트가 있다. Sql Server의  SQL Server Integration Services (혹은 DTS) 를 이용한다. 이 방법을 이용하려면, SSIS를 설치해서, DTS 패키지를 만든 후에, 이 DTS 패키지를 Job스케쥴러에 등록해서, Job을 실행시키면 된다. 단 SSIS가 설치된 컴퓨터에서 파일을 읽을 수 있어야 하고, 읽은 파일을 바로 DB의 테이블로 Export 시키기 위해서는 SQL Server의 계정이 sysadmin 서버역할이 부여되야 한다. 서버에 Excel을 직접 설치해서 COM을 이용해 읽는 것은 안 된다. Excel 프로그램이 무인실행을 위해 만들어진 프로그램이 아니기 때문에, 읽은 파일을 못 닫거나, 메모리 누수와 같은 문제가 발생할 수 있다. 구버전 파일의 경우 현실적으로 StackOverflow 에서처럼 ODBC 드라이버가 대세이지만,  ODBC를 이용해 읽는 방법은 32/64bit OS에 따라 다른 드라이버 를 설치해야 하고, ODBC 드라이버에서 각 컬럼의 데이타 타입을 유추할 때, 첫 몇 줄을 이용해서 판단하는데 조금 문제가 있다. 특히 셀 값을 텍스트로 입력하지 않으면(셀값의 앞에 apostrophe '를 붙히지 않으면) 포맷은 숫자지만 실제로는 텍스트 인데, 읽으면 숫자로 인식해버린다. 예를 들어 00033223 가 33223으로 읽히거나,  매우 긴 숫자면 Single/Double 타입...

IDisposable

Finalizer는 GC가 호출하는 거고, Dispose는 니가 직접 호출하는 거다. public class DisposeExample { // A class that implements IDisposable. // By implementing IDisposable, you are announcing that // instances of this type allocate scarce resources. public class MyResource: IDisposable { // Pointer to an external unmanaged resource. private IntPtr handle; // Other managed resource this class uses. private Component component = new Component(); // Track whether Dispose has been called. private bool disposed = false; // The class constructor. public MyResource(IntPtr handle) { this.handle = handle; } // Implement IDisposable. // Do not make this method virtual. // A derived class should not be able to override this method. public void Dispose() { Dispose(true); // This object will be cleaned up by the Dispose method. // T...