get names of parameters

  • Thread starter Thread starter parez
  • Start date Start date
P

parez

Hi All,

int a;
string b;
float c;

Test(a,b,c);

How do i get the the Test function to print a b c

public static Test(params object[] inputParams)
{

foreach (object inputParam in inputParams)
{
print(something);
}

}
 
You can't. Reflection, at best, will give you the fact that the Test
method has the inputParams parameter.

The only way you can do this is if you hook into the runtime, or if you
pass the names of the parameters and the values explicitly.

Hope this helps.
 
parez said:
int a;
string b;
float c;

Test(a,b,c);

How do i get the the Test function to print a b c

You can't. The called function has no clue where its values came from.
They may not even be variables.
 
You can't. The called function has no clue where its values came from.
They may not even be variables.

Thanks all for the reply!
I think i will pass the names to the function.
 
Nicholas Paldino said:
You can't. Reflection, at best, will give you the fact that the Test method has the
inputParams parameter.

The only way you can do this is if you hook into the runtime, or if you pass the names
of the parameters and the values explicitly.

Nicholas ,
Even the runtime has no clue about where these arguments came from, they are passed on the
stack or in a register and only the JIT has an idea where they came from at compile time.
Even using a low-level debugger with the symbol files (PDB) it's quite hard to find these
names back.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top