Domanda

Hi I do not know if this is possible or not but I have a c# Project lets say A and I am trying to access Assembly Info of another project B so that i can get Method Info of project B using Reflection. Problem is that i can not think of a way to integrate those two. Project A provides a openFileDialogue and it selects .csproj file. Reads it and extracts what files are being used in project B.

Can you suggest me a work out?

È stato utile?

Soluzione

I don't think you can do that by using reflection. To work with reflection you'll need an assembly, not csproj (or cs files). You should look for a parser, maybe use the Roslyn APIs, that will give you information about the source code in syntax tree format. http://blogs.msdn.com/b/visualstudio/archive/2011/10/19/introducing-the-microsoft-roslyn-ctp.aspx

Altri suggerimenti

Each .csproj file is XML, so you can read that in pretty easily. Listed in that file is every file included in the project, so you can parse the XML .csproj file to find all the .cs files.

From there, if you need to extract MethodInfo, you would have to either parse the .cs files, or use something like Roslyn to parse the code into its syntax tree, and find the methods that way.


Can you just use the built assembly (.exe or .dll) from "Project B" instead of its .csproj file? It would be a lot easier to load the assembly's reflection info, and just loop over every class and evey method...

Use Assembly.LoadFile to load directly the compiled assembly - i.e. the DLL or EXE; this will give you an Assembly object on which you can call GetTypes() etc. to access all the info you want.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top