첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
------------------------------------------------------------------------------------------------------------------------------------------------------
728x90
728x170

■ Type 클래스를 사용해 자식 클래스의 리스트를 구하는 방법을 보여준다.

 

▶ Type 클래스 : 자식 클래스 리스트 구하기 예제 (C#)

using System;
using System.Collections.Generic;

List<Type> typeList = GetChildClassList(typeof(System.Windows.Forms.Control));

foreach(Type type in typeList)
{
    Console.WriteLine(type.FullName);
}

 

▶ Type 클래스 : 자식 클래스 리스트 구하기 (C#)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

#region 자식 클래스 리스트 구하기 - GetChildClassList(sourceType)

/// <summary>
/// 자식 클래스 리스트 구하기
/// </summary>
/// <param name="sourceType">소스 타입</param>
/// <returns>자식 클래스 리스트</returns>
public List<Type> GetChildClassList(Type sourceType)
{
    return Assembly.GetAssembly(sourceType)
        .GetTypes()
        .Where(type => type.IsClass && !type.IsAbstract && type.IsSubclassOf(sourceType))
        .ToList();
}

#endregion
728x90
그리드형(광고전용)
Posted by icodebroker
,