tags:

views:

92

answers:

6

I am doing a code review on some large class libraries and I was wondering if anyone knows of an easy easy way to generate a list of all the methods (and possibly properties/variables too) and their access modifiers. For example, I would like something like this:

private MyClass.Method1()
internal MyClass.Method2()
public MyOtherClass.Method1()

Something kind of like a C++ header file, but for C#. This would put everything in one place for quick review, then we can investigate whether some methods really need to be marked as internal/public.

+1  A: 

Well, you can certainly use reflection for this, to enumerate the methods.

Lasse V. Karlsen
A: 

.Net Reflector or ildasm.

ildasm will generate a nice file for you if you ask it to export but only ask for the specific members you require.

NDepends will also do it (and with greater flexibility) but, for comercial use, costs money.

ShuggyCoUk
A: 

Exuberant ctags has a mode for C# and is easy to use. That said, I would just reflect the assembly.

Konrad Rudolph
+1  A: 

There are tools you can use, like Reflector

Patrick McDonald
+7  A: 

Yup, use reflection:

foreach (Type type in assembly.GetTypes())
{
    foreach (MethodInfo method in type.GetMethods(BindingFlags.Public |
        BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance))
    {
        Console.WriteLine("{0} {1}{2}.{3}", GetFriendlyAccess(method),
            method.IsStatic ? "static " : "", type.Name, method.Name);
    }
}

I'll leave GetFriendlyAccessName as an exercise to the reader - use IsFamily, IsPrivate, IsPublic, IsProtected etc - or the Attributes property.

Jon Skeet
Thanks Jon - this looks perfect.
Jon Tackabury
A: 

If you're using Visual Studio, then you can always get that view.

Just use the "Go to Definition" option and Visual Studio opens up the type metadata in a new tab (if you're using the DLL, and not the source code directly).