How should you complete the code?

DRAG DROP
You write the following code.

You need to get the list of all the types defined in the assembly that is being executed currently.
How should you complete the code? To answer, drag the appropriate code elements to the correct targets in
the answer area. Each code element may be used once, more than once, or not at all. You may need to drag
the split bar between panes or scroll to view content.
Select and Place:

DRAG DROP
You write the following code.

You need to get the list of all the types defined in the assembly that is being executed currently.
How should you complete the code? To answer, drag the appropriate code elements to the correct targets in
the answer area. Each code element may be used once, more than once, or not at all. You may need to drag
the split bar between panes or scroll to view content.
Select and Place:

Answer:

Explanation:
The AppDomain.CurrentDomain.GetAssemblies() gives you all assemblies loaded in the current application
domain.
The Assembly class provides a GetTypes() method to retrieve all types within that particular assembly.
Example: Using Linq:
IEnumerable<Type> types =
from a in AppDomain.CurrentDomain.GetAssemblies()
from t in a.GetTypes()
select t;
http://stackoverflow.com/questions/4692340/find-types-in-all-assemblies



Leave a Reply 5

Your email address will not be published. Required fields are marked *


Mo

Mo

Target 3 should be “Assembly”.

Oleg

Oleg

AppDomain
SelectMany
Assembly

Seamus

Seamus

public class Question12
{
public void GetAllAssembles()
{

List assemblies = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(x => x.GetTypes())
.Where(x=> x.IsClass && (x.Assembly == this.GetType().Assembly)).ToList();
foreach(Type type in assemblies)
{
Console.WriteLine(type.Assembly.FullName);
}
}
}

hed

hed

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

😉