0

Possible Duplicate:
c# Can I use reflection to inspect the code in a method?

So I am messing around with reflection and something struck me. Is it possible to view the code of a constructor obtained using the GetConstructor() method without navigating to the file and viewing it in visual studio. Is it possible for example to get the ConstructorInfo object and then print out the code that is associated with that constructor to the console window? Might seem a silly question but I have never really needed to look into reflection before so I am pretty new to it and am not sure as to how much it is capable of.

Also as a side note what is it that determins which constructor will be used as the default? Is it just the one with the least parameters?

Community
  • 1
  • 1
CSharpened
  • 11,674
  • 14
  • 52
  • 86

1 Answers1

3

Basically, code is only available in form of MSIL instructions. See Can I use reflection to inspect the code in a method? for more info.

Community
  • 1
  • 1
Oliver Hanappi
  • 12,046
  • 7
  • 51
  • 68
  • Thanks for that. Do you have an answer for the side note too? For example if I have no constructor declared with zero parameters how do I know which constructor is technically the default? – CSharpened Jul 09 '12 at 09:40
  • 1
    It's the same mechanism as method overloading. Consider a class having one constructor taking as single parameter an integer and another taking an object. If you create an object new MyClass(123) then the integer constructor will be used because the parameter passed is of type integer and therefore the integer constructor fits best. – Oliver Hanappi Jul 09 '12 at 09:44