You can display the actual source code from codebehind on an aspx page (for sample code pages)

I am working on creating an aspx page to display library code usage examples.

So, basically, I would like, for example: Description Source code Exit button (in datagrid)

Instead of copying and pasting the code from the button onto the aspx page for display, I thought it would be nice to be able to read the actual source code at runtime and display it. Besides the fact that it would be a stain, it would have the added benefit of ensuring that the source code is up to date, while copy and paste can become outdated if someone makes a change and forgot to refresh the aspx page with the new code.

I can imagine two possible ways to do this: 1) (kludgy). Deploy the code behind the files, which can then be read at runtime, and the corresponding function code can be parsed and displayed. 2) (Preferred) Runtime decompiles the DLL (as a reflector) and displays the code.

So, I know how to make # 1, but I don’t know about No. 2 (if that’s even possible).

+3
source share
3 answers

Decompiling the code at runtime will not give you exact code like what you wrote. At this moment, he becomes more of an interpretation.

- . . 1, .cs .

+5

- , IMO - , , , . - Reflector, , , , , , .

( ), # - . , , . ( , .)

+3

If you want to keep comments and original variable names, then reflection will not work. Parsing the code is likely to be the most direct way to do this. It may also be possible to extract data from PDB files.

0
source

Source: https://habr.com/ru/post/1704146/


All Articles