Get Loaded Assemblies - CSharp System.Reflection

CSharp examples for System.Reflection:Assembly

Description

Get Loaded Assemblies

Demo Code


using System.Reflection;
using System.Linq;
using System.IO;// w  ww.  j  av a 2s.  c o  m
using System.Diagnostics;
using System.Collections.Generic;
using System;

public class Main{


        private static Dictionary<string, Assembly> GetLoadedAssemblies(string assemblyPrefix)
        {
            return AppDomain.CurrentDomain
                            .GetAssemblies()
                            .Where<Assembly>(a => a.FullName.StartsWith(assemblyPrefix)).ToDictionary<Assembly, string>(a => a.GetName().Name);
        }


        public static IEnumerable<Assembly> GetAssemblies(string assemblyPrefix)
        {
            IEnumerable<Assembly> assemblies;
            if (string.IsNullOrWhiteSpace(assemblyPrefix))
                assemblies = AppDomain.CurrentDomain.GetAssemblies().AsEnumerable();
            else
                assemblies = AppDomain.CurrentDomain.GetAssemblies()
                    .Where<Assembly>(a => a.FullName.StartsWith(assemblyPrefix));
            return assemblies;
        }
}

Related Tutorials