Inline scripts

XSharper can run scripts directly from command line, which is often faster than dealing with files, and replaces interactive mode. There are three special switches:

/// <expression> (Run)

Evaluate expression from /// until the end of the line. By default it is treated as a piece of C# code:


Usually it's a good idea to wrap everything into double quotes (so <, > and " characters are not interpreted by command line interpreter).

XSharper command-line processing code replaces ` (back quote) with " in the expression to keep it simpler. In the unfortunate event you do need the ` character, just use "\x60" in C# code, or (char)0x60 in XSharper multi-expressions (there is no escaping there).


Print ASCII table of the first 96 printable characters (by generating array of bytes and calling XSharper.Core.Utils.ToHexDump on it):

If the expression starts with < it is treated as XML


Finally, if the expression starts with =, it is treated as interpreted multi-expression with relaxed rules


Quotes and command line arguments in inline scripts

Aside of protecting from the wrongdoings of Windows command processor, if the first character of the expression is ", only the string inside the quotes is considered to be a script, and the rest are treated as arguments that can be accessed via ${=$argv[0]}, ${=$argv[1]} and so on. This looks a bit confusing but allows writing simple one liners with arguments.

For example, display the length of file passed as first argument:

If the first character is not ", expression is evaluated until the end of the line:

Additional assemblies

Also, additional assemblies may be specified in the command line as an assembly name, or DLL path. Multiple names may be specified in comma or semicolon separated list.

Load the image specified in the first command line argument and copy it to clipboard:

Actually the code above may be shortened via prefixing assembly names with @, which adds assembly names into default namespace (does the right thing for Windows.Forms, System.Diagnostics where namespace matches assembly name):

And now, with one more parameter, we produce a complete utility img2clipboard (more about it in Compiling scripts):

///p <expression> (Print)

Evaluate expression (either C#, or multi-expression if starts with =) that returns value, and write the value with WriteLine .

Read c:\windows\win.ini and print each line within [[ ... ]]:

Print first 64 bytes of explorer.exe as HEX dump:

///# <expression> (Dump)

Evaluate expression (either C#, or multi-expression if starts with =) that returns value, and dump the value.

Using standard input

In some special cases it may be useful to read script from standard input, instead of the command line. In that case specify - (minus) instead of the expression.