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