Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get the variable name
#2
Code:
Copy      Help
// script "test ClassA.cs"
/*/ c \ClassA.cs; /*/

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, object[] args, [CallerArgumentExpression("args")] string e_ = null)
    {

        print.it(inp);
        
        //print.it(e_);
        var k = e_[1..^1].Split(',', StringSplitOptions.TrimEntries);
        for (int i = 0; i < args.Length; i++) {
            print.it($"{k[i]} = {args[i]}");
            //print.it($"{k[i]} = {print.util.toString(args[i], true)}"); //this also prints array element etc, like print.it
        }
    }
}

It is the only possible way. With params not possible.


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: 1 Guest(s)