Ms. Corlib
Ms. Corlib

Reputation: 5213

How can I get the name type of a parameter at runtime?

So I have a MethodInfo object m that I'm testing and I want to extract the type of a parameter. For instance, I want "int" and string from the following.

public void SomeMethod ( int i, string s )
{
   // ... 
}

When I run

ParameterInfo pinf = m.GetParameters.FirstOrDefault(p => p.Name == "i"); 

then

ping.GetType().Name 

it returns "RuntimeParameterInfo".

So what do I actually need to be doing to get "int"?

This is an example I made up, but the idea comes from a unit test I'm writing.

Upvotes: 0

Views: 203

Answers (2)

Scott Hannen
Scott Hannen

Reputation: 29217

ping.ParameterType

Gets the Type of this parameter.

Upvotes: 1

MarcinJuraszek
MarcinJuraszek

Reputation: 125620

Use ping.ParameterType.Name instead.

ParameterInfo.ParameterType Property

Gets the Type of this parameter.

Upvotes: 1

Related Questions