Is it possible to show all methods and their access modifiers?

I am reviewing code in some large class libraries, and I was wondering if anyone knew of a simple way to create a list of all methods (and possibly properties / variables) and their access modifiers. For example, I would like something like this:

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

Something like a C ++ header file, but for C #. This will put everything in one place for a quick overview, then we can find out if some methods really need to be marked as internal / public.

+3
source share
6 answers

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 will leave GetFriendlyAccessName as an exercise for the reader - use IsFamily, IsPrivate, IsPublic, IsProtected, etc. or the Attributes property.

+9
source

Well, you can, of course, use reflection for this to list methods.

+1
source

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

+1
source

There are tools you can use, such as Reflector

+1
source

.Net Reflector or ildasm.

ildasm will create a good file for you if you ask it to export, but just ask about the specific members that you need.

NDepends will also do this (and with more flexibility), but for commercial use it costs money.

0
source

If you use Visual Studio, you can always get this view.

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

0
source

Source: https://habr.com/ru/post/1344130/


All Articles