How can I find the .cs file which contains a specified class in a project by code?
I imagine it could look like this:
string pathToFoo = ClassFileFinder.FindClassPath(typeof(Foo));
How can I find the .cs file which contains a specified class in a project by code?
I imagine it could look like this:
string pathToFoo = ClassFileFinder.FindClassPath(typeof(Foo));
Are you trying to modify the file at runtime? That's not a very good idea and a huge security concern. You could always try to use System.Reflector to see the contents of the class at runtime. Also, if you're wanting to add a function to a class that is in a library, you can use an extension method.
It does not make any sense what you are trying to do. You wont have any .cs file in compiled executable at the end.
Moreover, you may have different class filenames than class identifers declared in class definitions so I doubt simple file search will also not guarantee finding file in source code. So IMO its not possible.
I have written and tested the class based on some ideas I had and in found in the comments. It works reasonably fast and I haven't found any problems with it so far.
}