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

■ 특정 인터페이스를 구현한 모든 타입을 구하는 방법을 보여준다.

 

▶ 특정 인터페이스를 구현한 모든 타입 구하기 예제 (C#)

using System;
using System.Collections;
using System.Collections.Generic;

Assembly assembly = Assembly.LoadFrom(@"D:\DevExpress.XtraEditors.v19.2.dll");

IEnumerable<Type> typeEnmerable = GetTypeEnumerable(assembly, typeof(IList));

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

 

▶ 특정 인터페이스를 구현한 모든 타입 구하기 (C#)

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

#region 타입 열거 가능형 구하기 - GetTypeEnumerable(assembly, interfaceType)

/// <summary>
/// 타입 열거 가능형 구하기
/// </summary>
/// <param name="assembly">어셈블리</param>
/// <param name="interfaceType">인터페이스 타입</param>
/// <returns>타입 열거 가능형</returns>
public IEnumerable<Type> GetTypeEnumerable(Assembly assembly, Type interfaceType)
{
    IEnumerable<Type> typeEnumerable = assembly.GetTypes()
        .Where(y => interfaceType.IsAssignableFrom(y) && !y.IsInterface);

    return typeEnumerable;
}

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