In C# is there a way to convert a function’s source code to a string? Sort of like how it can be done in JavaScript. I need this because I’m writing some documentation for an Asp.Net control and want to show the original source code next to the result, without copy/pasting it.
Share
Short answer: no.
Long answer: you can generate something at compile time with MSBuild tasks, T4 templates, or manually parsing stuff, or using Roslyn to parse it for you.
If you need the source code at runtime though, you’ll surely need to include the cs files in the deployed stuff, because there is no stable way of getting the code back. (You could try runtime decompilation though, but that will look “ugly” and not very precise.)