Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Chaining params function calls

Is it possible in C# to accept a params argument, then pass it as params list to another function? As it stands, the function below will pass args as a single argument that is an array of type object, if I'm not mistaken. The goal here is self evident.

//ScriptEngine
public object[] Call(string fnName, params object[] args)
{
    try{
        return lua.GetFunction(fnName).Call(args);
    }
    catch (Exception ex)
    {
        Util.Log(LogManager.LogLevel.Error, "Call to Lua failed: "+ex.Message);
    }
    return null;
}

The lua.GetFunction(fnName).Call(args); is a call to outside of my code, it accepts param object[].

like image 644
selkathguy Avatar asked Nov 23 '25 19:11

selkathguy


1 Answers

If the signature of the Call method you're calling accepts a params object[] args then you are mistaken. It doesn't consider args a single object of thpe object, to be wrapped in another array. It considers it the entire argument list, which is what you want. It'll work just fine exactly as it stands.

like image 51
Servy Avatar answered Nov 26 '25 10:11

Servy