Getting a specific method source code from .cs file (at runtime)

后端 未结 3 649
北荒
北荒 2020-12-18 07:01

1 - I have this file content on the disc (cs file, not compiled):

    namespace Test
    {
        using System;
        public class TestCl         


        
3条回答
  •  臣服心动
    2020-12-18 07:55

    The .NET Reflection class does not support decompiling to C#. The best you can do is use MMethodInfo.GetMethodBody() and call MethodBody.GetILAsByteArray() on the response. That will give you the MSIL which is the best that .NET reflection can give you.

    To decompile to C# you will need a decompiler - of which there are at least a dozen legitimate options. You'll need to investigate for one that meets your requirements and budget.

    One option is Red Gate's .NET Reflector. Nick Harrison has a long and thorough article on using .NET Reflector in an application to render source code as HTML.

提交回复
热议问题