Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get the variable name
#1
I want to retrieve and print each variable name from the parameters passed in a class. (My expression may not be clear enough, please refer to the comments in the code)

I searched for relevant information on Google and the suggestion I got was to use the callstack! However, I haven't been able to implement it yet. There might be a simpler method

I previously had a similar feature request in QM, but it was not resolved. 

Thank you in advance for any suggestions and Help
David
 
Code:
Copy      Help
// script "ClassA_Test.cs"
/*/ role exeProgram; outputPath %folders.Desktop%\ClassA; c ClassA.cs; /*/ //.
script.setup(trayIcon: true, sleepExit: true);
//..

string inp = "Hi";

string S1 = "hello world";

int I1 = 888;

string[] AS1 = { "hello", "world" };

ClassA.FuncA(inp, S1, I1, AS1);

Code:
Copy      Help
// class "ClassA.cs"

public class ClassA
{
    
    public static void FuncA(string inp, params object[] args)
    {

        print.it(inp);
        
        //Get the variable name passed as an argument to a function
        print.it($"fist Arg variable name: ?"); // ? -> It should output S1
        
        print.it($"Second Arg variable name: ??"); // ?? -> It should output I1
        
        print.it($"Third Arg variable name: ???"); // ??? -> It should output AS1
    }
}


Messages In This Thread
Get the variable name - by Davider - 03-18-2024, 11:40 PM
RE: Get the variable name - by Gintaras - 03-19-2024, 08:23 AM
RE: Get the variable name - by Davider - 03-19-2024, 09:48 AM
RE: Get the variable name - by Davider - 03-20-2024, 01:23 AM
RE: Get the variable name - by Gintaras - 03-20-2024, 08:17 AM
RE: Get the variable name - by Davider - 03-20-2024, 08:21 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)