P
P
Paul2016-11-04 14:44:43
Programming
Paul, 2016-11-04 14:44:43

How to get a list of methods, properties, fields, events, classes, structures, interfaces in C#?

Hi everybody!
I myself have found two ways so far: 1 - reflection, 2 - a self-written parser, reflection is a more correct option, as it seems to me, but limited by the fact that it provides only "declarations" of methods, classes, etc., to access the contents of the bodies of elements there is no possibility. The self-written parser is not limited in anything, but it would still be interesting to know what other ways there are to get functional elements?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stanislav Makarov, 2016-11-04
@Nipheris

Your two methods are completely different solutions. Using reflection, you can get information about entities (methods, properties, classes, fields, ...) in already compiled assemblies. Reflection does not work and cannot work with the source code in any way. With a "self-written parser" (in general, I would advise you to take Roslyn compilers) you can process the source code and get everything you need from it, but then you need the actual source code.
What problem are you solving?

M
MrDywar Pichugin, 2016-11-04
@Dywar

Roslyn - everything is already done.
https://youtu.be/jWyYs_LJDPU?t=1872

A
Andrew, 2016-11-04
@impwx

There is also Mono.Cecil - an alternative implementation of reflection that allows you to "pick" any assembly, or create your own. In particular, you can get the IL-code of methods. Of course, you won't get the source code in C#, but you can still analyze it. Based on Mono.Cecil, for example, the IlSpy decompiler is made.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question