문제

I know using reflection that I can find the list of classes within a single assembly (such an example is How to get all classes in current project using reflection?).

Is there a way to do this with just public classes within a given directory?

도움이 되었습니까?

해결책

I assume you mean a directory that contains one or more assemblies, if so you can do it like this:

var types = new List<Type>();

var paths = Directory.GetFiles("directoryPath", "*.dll", SearchOption.TopDirectoryOnly);

foreach(var path in paths)
{
    types.AddRange(Assembly.LoadFrom(path).GetTypes());
}

GetTypes method uses BindingFlags.Public and BindingFlags.Instance by default.So you don't need to specify BindingFlags parameter additionally.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top