get names of parameters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • parez

    get names of parameters

    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 );
    }

    }

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: get names of parameters

    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.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "parez" <psawant@gmail. comwrote in message
    news:1175103749 .300751.42880@y 66g2000hsf.goog legroups.com...
    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 );
    }
    >
    }
    >

    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: get names of parameters

      parez <psawant@gmail. comwrote:
      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.

      --
      Jon Skeet - <skeet@pobox.co m>
      http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
      If replying to the group, please do not mail me too

      Comment

      • parez

        #4
        Re: get names of parameters

        On Mar 28, 2:36 pm, Jon Skeet [C# MVP] <s...@pobox.com wrote:
        parez <psaw...@gmail. comwrote:
        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.
        >
        --
        Jon Skeet - <s...@pobox.com >http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
        If replying to the group, please do not mail me too
        Thanks all for the reply!
        I think i will pass the names to the function.

        Comment

        • Willy Denoyette [MVP]

          #5
          Re: get names of parameters

          "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote in message
          news:eMCrsGWcHH A.264@TK2MSFTNG P05.phx.gbl...
          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.


          Comment

          Working...