/src/LinFu.Reflection/TypeExtractor.cs

http://github.com/philiplaureano/LinFu · C# · 33 lines · 22 code · 2 blank · 9 comment · 0 complexity · edeb357fa6db98397ab1fb3ee5c7940c MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. namespace LinFu.Reflection
  5. {
  6. /// <summary>
  7. /// Represents a type that can extract <see cref="System.Type" />
  8. /// objects from an <see cref="Assembly" /> instance.
  9. /// </summary>
  10. public class TypeExtractor : ITypeExtractor
  11. {
  12. /// <summary>
  13. /// Returns a set of types from a given assembly.
  14. /// </summary>
  15. /// <param name="targetAssembly">The <see cref="Assembly" /> that contains the target types.</param>
  16. /// <returns>An <see cref="IEnumerable{T}" /> of types from the target assembly.</returns>
  17. public IEnumerable<Type> GetTypes(Assembly targetAssembly)
  18. {
  19. Type[] loadedTypes = null;
  20. try
  21. {
  22. loadedTypes = targetAssembly.GetTypes();
  23. }
  24. catch (ReflectionTypeLoadException ex)
  25. {
  26. loadedTypes = ex.Types;
  27. }
  28. return loadedTypes;
  29. }
  30. }
  31. }