0

i was wondering if it is possible to retrieve implementation of a class via Reflection or perhaps via other way around.

for example i have this code :

 public class class1
    {
        private string Name { get; set; }

        private void DoSomethng()
        {
            string s = "I'm setting up this ";
        }
    }

and i would like to have the implementation of DoSomething as a string or so is it possible ?

Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
  • 2
    `i was wondering if it is possible to retrieve implementation of a class`...yes it is. Please clarify what you mean with you other questions. – Thomas D. Feb 06 '17 at 23:04
  • If you don't mind it being in the form of a CIL byte array you can just get the MethodInfo for DoSomething and call GetMethodBody. If however you want it in C#, well, I've personally made sure that not every .NET method body can even be expressed in C# >:D – hoodaticus Feb 06 '17 at 23:06
  • You could turn IlSpy against itself and then figure out how it turns CIL code into C#. Though this is not 100% flawless - it does amusing things for instance when you do things in CIL that are impossible in C#. – hoodaticus Feb 06 '17 at 23:15
  • Have you checked this https://msdn.microsoft.com/en-us/library/system.reflection.methodbase.getmethodbody(v=vs.110).aspx ? – H. Herzl Feb 06 '17 at 23:16
  • I would like to have exact implementation not CIL code converted or something like that more like if i had exac implementation of a class inclusive property names, methods full implementation etc. but i guess thats impossible. – Arman Nagaepetian Feb 06 '17 at 23:38

0 Answers0