Get Types Safely from Assembly - CSharp System.Reflection

CSharp examples for System.Reflection:Assembly

Description

Get Types Safely from Assembly

Demo Code


using System.Reflection;
using System.Linq;
using System.Collections.Generic;
using System;//from  w w  w  . ja v a2 s. co m

public class Main{
        public static IEnumerable<Type> GetTypesSafely(this Assembly assembly)
        {
            try
            {
                return assembly.GetTypes();
            }
            catch (ReflectionTypeLoadException ex)
            {
                return ex.Types.Where(x => x != null);
            }
        }
}

Related Tutorials