Loop through the assemblies that current application references - CSharp Custom Type

CSharp examples for Custom Type:Assembly

Description

Loop through the assemblies that current application references

Demo Code

using System;/*w  w  w. j a  v a2  s  . co m*/
using System.Linq;
using System.Reflection;
class Program
{
    static void Main(string[] args)
    {
        foreach (var r in Assembly.GetEntryAssembly().GetReferencedAssemblies())
        {
            var a = Assembly.Load(new AssemblyName(r.FullName));
            int methodCount = 0;
            foreach (var t in a.DefinedTypes)
            {
                methodCount += t.GetMethods().Count();
            }
            Console.WriteLine($"{a.DefinedTypes.Count():N0} types " + $"with {methodCount:N0} methods in {r.Name} assembly.");
        }
    }
}

Result


Related Tutorials