views:

85

answers:

3

I googled and someone found the answer and linked but it was dead. How can i find a specific class in a specific file? The poster i found ask that question and found how to do it in a namespace but i would like to find one specific to a file. This question is to answer my other question but now that i thought of this i would like to know the answer.

A: 

If you want to find the source code for a class, use the Go To Definition option in Visual Studio.

Once the code is compiled, it's not arranged in files, it's arranged in name spaces and assemblies. If it's at all possible to find out from which source file a class originated, you would have to loop through all classes and look for it.

Guffa
+2  A: 

Something like this?

string path = "INSERT PATH HERE";

var assembly = Assembly.LoadFile(path);
foreach (var type in assembly.GetTypes())
{
    Debug.WriteLine(type.Name);

    // do check for type here, depending on how you wish to query
}
MPritch
Close enough. I figure this out from the above. var type = typeof(User); var assembly = type.Assembly; var configType = assembly.GetType(type.Namespace + ".MyConfig");
acidzombie24
+1  A: 

I am not sure how the file name shall be stored as part of compiled assembly. Other option is that you can use the PDB file generated by the VS IDE to get the source file at some extension.

Here is some internals of pdb file.

http://www.informit.com/articles/article.aspx?p=22685

Once you can parse the file, you can use the symbol and look at the source definition.

I am glad to know other ways as well.

Gopalakrishnan Subramani