C # API Generator

I have several DLL files and I want to export all public classes using methods separated by namespaces (export to html / text file or something else that I can ctrl + c / v on Windows :)).

I do not want to create documentation or combine my dlls with an XML file. I just need a list of all public methods and properties.

What is the best way to do this?

TIA for any answers

+5
source share
3 answers

Very rough around the edges, but try this for size:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace GetMethodsFromPublicTypes
{
    class Program
    {
        static void Main(string[] args)
        {
            var assemblyName = @"FullPathAndFilenameOfAssembly";

            var assembly = Assembly.ReflectionOnlyLoadFrom(assemblyName);

            AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(CurrentDomain_ReflectionOnlyAssemblyResolve);

            var methodsForType = from type in assembly.GetTypes()
                                 where type.IsPublic
                                 select new
                                     {
                                         Type = type,
                                         Methods = type.GetMethods().Where(m => m.IsPublic)
                                     };

            foreach (var type in methodsForType)
            {
                Console.WriteLine(type.Type.FullName);
                foreach (var method in type.Methods)
                {
                    Console.WriteLine(" ==> {0}", method.Name);
                }
            }
        }

        static Assembly CurrentDomain_ReflectionOnlyAssemblyResolve(object sender, ResolveEventArgs args)
        {
            var a = Assembly.ReflectionOnlyLoad(args.Name);
            return a;
        }
    }
}

Note. This requires refinement to exclude getters / seters properties and inherited methods, but this is a decent starting place

+6
source

.NET Reflector RedGate. .

+1

All Articles