public static IEnumerable<Type> GetAccessibleTypes(this Assembly assembly)
{
try
{
#if NET40
return assembly.GetTypes();
#else
return assembly.DefinedTypes.Select(t => t.AsType());
#endif
}
catch (ReflectionTypeLoadException ex)
{
// The exception is thrown if some types cannot be loaded in partial trust.
// For our purposes we just want to get the types that are loaded, which are
// provided in the Types property of the exception.
return ex.Types.Where(t => t != null);
}
}
What are differences between assembly.GetTypes()
and assembly.DefinedTypes.Select(t => t.AsType())
?
Original code: https://entityframework.codeplex.com/SourceControl/latest#src/Common/AssemblyExtensions.cs