Gets the loadable types. - CSharp System

CSharp examples for System:Type

Description

Gets the loadable types.

Demo Code


using System.Threading.Tasks;
using System.Text;
using System.Reflection;
using System.Linq;
using System.Collections.Generic;
using System;/*w  w w .j a va  2 s  .com*/

public class Main{
        /// <summary>
      /// Gets the loadable types.
      /// </summary>
      /// <param name="assembly">The assembly.</param>
      /// <returns>Returns an IEnumerable of Types that can be loaded.</returns>
      /// 
      public static IEnumerable<Type> GetLoadableTypes(this Assembly assembly) {
         try {
            return assembly.GetTypes();
         } catch(ReflectionTypeLoadException e) {
            return e.Types.Where(t => t != null);
         }
      }
}

Related Tutorials