Pass/Share Arguments within CSX Files

Отвечено Pass/Share Arguments within CSX Files

  • 12 июля 2012 г. 17:31
     
     

    I'm trying to learn more about the new CSX files to script with C# and Roslyn.

    1.) Are there any examples on how to pass arguments to a CSX file?

    2.) Is there a way to share variables between CSX files? Meaning, if File1 has a global string strTest;,  could File2 see/use strTest?

    Any docs, links, etc. would help.

    Thanks in advance.

Все ответы

  • 12 июля 2012 г. 18:15
    Владелец
     
     Отвечено

    Hi, shaggygi.  If you see my post pinned to the top of the forum, I've posted the spec (which does lead implementation in places and can change before we actually ship).

    We've adopted the "--" pattern for designating what on the command line is intended for the script and what is not.  Items on the command line before the "--" are assumed to be switches and .csx or .cs files for processing.  Items after the "--" are intended for the script to pick off.  While we're considering a special global called "args" for accessing the command line tokens after the "--", we haven't settled on any direct support, but the spec shows these two lines of code for accessing what's after the "--":

    var args = Environment.GetCommandLineArgs()

    args = args.Skip(args.IndexOf(args, “--") + 1).ToArray()

    All files passed together on the csi.exe command line are compiled together into a single <Script> class, so all top-level script variables, function definitions, type declarations, etc., from all files are effectively members of the same <Script> class.  We describe the variables as "script variables" in that they are more like closure variables that the top-level functions have closed over.  All the top-level functions and properties can refer to each other.

    Cheers,

    Bill

    • Помечено в качестве ответа shaggygi 14 июля 2012 г. 18:43
    •