Mark Smethwick
Mark Smethwick

Reputation: 3

System.Reflections - CSharp Interpreteur

I am trying to make a little app which reads codes (given files) and must parse them. It may not compile, because the code I am providing is already compiled. What I need is that I can read all infos of the code using something similar to System.Reflections (FieldInfo, MethodInfo, ...).

I have tried compiling that code as a DLL and then use:

((Assembly)assembly).GetExportedTypes()[x].GetMethods ();
((Assembly)assembly).GetExportedTypes()[x].GetFields ();

It does a lot of the work, but I am facing the problem that it gives me Only the public declarations: (only the public methods, and public fields) I am unable to read less access declarations, (private, internal, protected).

How can I obtain this?

Additional Info: I just need the names and the types of the declarations

{methodType, methodName, variableType, variableName}

Upvotes: 0

Views: 48

Answers (2)

sszarek
sszarek

Reputation: 424

You should pass BindingFlags to your GetMethods/GetFields etc. calls. Read this: link.

Upvotes: 0

Selman Genç
Selman Genç

Reputation: 101701

You need to use BindingFlags:

var flags = BindingFlags.Instance | BindingFlags.NonPublic;
((Assembly)assembly).GetExportedTypes()[x].GetMethods(flags);

Upvotes: 2

Related Questions