Skip to content

Equivalent for AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes()) #4212

Closed
@DmitrySikorsky

Description

@DmitrySikorsky

Hi! I have to get all implementations (classes) of some interface. How I can do that? Now I only can to make it for current assembly (project), but the goal is to have it in separate project:

public T GetRepository()
{
foreach (Type type in typeof(T).GetTypeInfo().Assembly.GetTypes())
if (typeof(T).IsAssignableFrom(type) && type.GetTypeInfo().IsClass)
return (T)Activator.CreateInstance(type);

return default(T);
}

Metadata

Metadata

Assignees

Labels

area-AssemblyLoader-coreclrquestionAnswer questions and provide assistance, not an issue with source code or documentation.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions