■ Nullable 타입 여부 구하기 예제

----------------------------------------------------------------------------------------------------

using System;

 

Type sourceType = typeof(int?);

 

Console.WriteLine(IsNullableType(sourceType));

----------------------------------------------------------------------------------------------------

 

■ Nullable 타입 여부 구하기

----------------------------------------------------------------------------------------------------

using System;

 

#region Nullable 타입 여부 구하기 - IsNullableType(sourceType)

 

/// <summary>

///  Nullable 타입 여부 구하기

/// </summary>

/// <param name="sourceType">소스 타입</param>

/// <returns>Nullable 타입 여부</returns>

public bool IsNullableType(Type sourceType)

{

    return sourceType.IsGenericType && sourceType.GetGenericTypeDefinition() == typeof(Nullable<>);

}

 

#endregion

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요