I would like to know if it’s possible to retrieve the .cs file that contains a certain class at runtime.
Ex. I have the “Type” that represents my class (public class Foo) and from that, I would like to retrieve the path to its parent file (“c:\foo.cs”).
Thanks
Edit: The purpose of this would be to show some classes’ name to the user in a ListView (populated programmatically) for example and when he double clicks on one of the ListViewItem, it opens the .cs file that contains the class in question.
It is possible, but there is no ‘magic’ way that I know of. You’ll have to add a method to every type you want to support this. Also it will only work if the .pdb file is available. _GetSourceFileName returns null without it.
// Some other file
// Yet another other file