0

I'm digging around in C# reflection but have encountered a problem.

If I reflect over the following method with the intent of retrieving the parameter types, then i'm unable to get the base type when the parameter have either the out or ref:

public void MyMethod(out int first, ref string second) {  }

The two parameter types returned are:

System.Int32&
System.String&

How do i get the base method in code, that is without the Ampersand postfixed?

Here are the boiled down way i retrieve the parameters:

typeof(MyClass).GetMethod(MyMethod().GetParameters().Select(p => p.ParameterType)
Anders
  • 1,590
  • 1
  • 20
  • 37
  • 2
    I think this https://stackoverflow.com/questions/3033639/reflection-how-to-get-the-underlying-type-of-a-by-ref-type contains the answer to your question :) Let me know if it does, so that we can close it as a dupe – Yeldar Kurmangaliyev Dec 21 '18 at 10:51
  • @YeldarKurmangaliyev: Hot diggity that was a homerun!! Thanks for the link :-) – Anders Dec 21 '18 at 11:32

0 Answers0