잊지 않겠습니다.

Complier warning may not be benign

Compiler에서의 경고를 무시하지 말아라. Compiler에서의 경고는 모두다 없애는 것이 가장 우선되는 일이 된다.

Treat warnings as errors option을 활성화시키고 나서 compile하는 것이 좋다.

모든 project의 수행시에, 이 옵션을 활성화 시키고 나서 시작하는 것이 유용하다.

   

Ordering of catch processin isn't consist across languages

try~catch 구문에서 C#과 VB.NET의 동작 방법은 다르다.

C#에서는 위에서부터 아래로 넘어갈 수록, 범위가 낮은 exception class로 넘어가게 되지만, VB.NET에서는 exception class로 바로 jump 하게 된다.

static void Main(string[] args)
{
 try
 {
  AMethod();
 }
 catch(Exception ex)
 {
  Console.WriteLine(ex.Message);
 }
 catch(ApplicationException ex)
 {
  Console.WriteLine(ex.Message); <- 절대 수행될 수 없다.
 }
}

   

Type.GetType() might fail at run-time

Type.GetType() 보다는 typeof/GetType를 주로 사용하는 것이 좋다.

   

rethrow isn't consistent

catch(Exception ex)으로 잡힌 error를 throw ex로 해서 다시 던지게 될 경우에는 exception안의 정보를 잃어버릴 수 있다. 이럴때는 catch(Exception)에서 throw로 다시 던져주거나, throw ex.InnerException을 이용해서 Exception을 보내주는 것이 좋다.

   

Versioning may lead to Serialization headaches

: 이미 Serialization된 객체에 대해서 객체의 또다른 member 변수등의 변경이 생겼을 때에, 기존의 serialization의 데이터를 불러오는 데에 문제가 생기게 된다. 이때에, exception을 사용해서 하는 방법도 있으나, 가장 좋은 것은 아래 코드와 같이 Helper를 이용해서 객체의 데이터를 Type의 이름에 따라 얻어오는 방법이다.

  public class SerializationHelper
  {
    /// <summary>
    /// Desirialization이 될때에, 호출을 시켜서 새로 생성되는 객체에 값을 채워주는 함수.
    /// 각각을 enumerator에서 MoveNext로 움직이는 것으로 모든 객체의 값을 얻어온다.
    /// 만약에 구버젼의 Serialization 객체인 경우에는 그 값이 없기 때문에 채워지지 않고,
    /// 기본 값을 얻어오게 된다.
    /// </summary>
    /// <param name="theType"></param>
    /// <param name="instance"></param>
    /// <param name="info"></param>
    public static void SetData(Type theType, Object instance, SerializationInfo info)
    {
      SerializationInfoEnumerator enumerator = info.GetEnumerator();

      while(enumerator.MoveNext())
      {
        string fieldName = enumerator.Current.Name;
        FieldInfo theField =
          theType.GetField(fieldName,
                           BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public |
                           BindingFlags.NonPublic);

        if ( theField != null )
        {
          theField.SetValue(instance, enumerator.Value);
        }
      }
    }

    /// <summary>
    /// Serialization이 될 때에 불러지는 함수
    /// Instance의 모든 값들을 얻어와서 Serialization을 행한다.
    /// </summary>
    /// <param name="theType"></param>
    /// <param name="instance"></param>
    /// <param name="info"></param>
    public static void GetData(Type theType, Object instance, SerializationInfo info)
    {
      FieldInfo[] fields =
        theType.GetFields(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public |
                          BindingFlags.NonPublic);

      foreach(FieldInfo fieldInfo in fields)
      {
        if(!fieldInfo.IsNotSerialized)
        {
          info.AddValue(fieldInfo.Name, fieldInfo.GetValue(instance));
        }
      }
    }
  }

  

Create Web apps can be painful

blank solution을 만들어 준 후에, 그 안에 project를 만들어주는 것이 project를 만들어주는 것으로 시작하는 것보다 더 낫다.

  • 디자인 된 solution에 원하는 project를 넣는 것이 가능하다. (source의 src, test의 구분이 더 쉬워진다.)
  • 여러 solution에 결합되어 있는 project들의 관리가 보다 용의하다.

IIS에서 virtual directory를 미리 만들어두고, 웹사이트를 만들어주고, 개발을 행하는 것이 훨신더 편한 방법으로 web site의 개발이 가능해진다.

  

Naming XML documentation for IntelliSense support isn't intuitive

XML-style documentation으로 만들어진 code에 대한 xml format은 자동적으로 Visual studio의 intellisense에서 사용되어질 수 잇다. 그렇지만, 하나의 제약으로 가질수 있는 것이, assembly name과 xml file의 이름을 동일하게 해줄 필요가 있다. 자동적으로 찾지는 못한다.

Posted by Y2K
,