Merge pull request #3678 from mono/seq-read
[mono.git] / man / csharp.1
index 6466bfe060085a0d1389e3b748ab72e71ffdf12d..a0f9e6f4f6acd62c6df19b1a0a84aadca07e306c 100644 (file)
@@ -4,22 +4,62 @@
 ..
 .TH csharp 1 "4 September 2008"
 .SH NAME 
-csharp \- Interactive C# Shell 
+csharp, gsharp \- Interactive C# Shell 
 .SH SYNOPSIS
-.B csharp 
+.B csharp [--attach PID] [-e EXPRESSION] [file1 [file2]]
 [options] 
+.P
+.B gsharp [file1 [file2]]
 .SH DESCRIPTION
 The 
 .I csharp
 is an interactive C# shell that allows the user to enter and evaluate
-C# statements and expressions from the command line.
-.PP
-This command is a shortcut to invoke the 
-.I gmcs
-command with the 
-.I \-\- shell 
-command line option.   All of the regular compiler options available
-to gmcs are available in the interactive shell.
+C# statements and expressions from the command line.   The regular 
+.I mcs
+command line options can be used in this version of the compiler. 
+.PP
+The 
+.I gsharp
+command is a GUI version of the C# interpreter that uses Gtk# and
+provides an area to attach widgets as well.      This version can be
+attached to other Gtk# applications in a safe way as it injects itself
+into the main loop of a Gtk# application, avoiding any problems
+arising from the multi-threaded nature of injecting itself into a
+target process.
+.PP
+Files specified in the command line will be loaded and executed as
+scripts.
+.PP
+Starting with Mono 2.10, the 
+.I csharp
+command can be used as an interpreter executed by executables flagged
+with the Unix execute attribute.   To do this, make the first line of
+your C# source code look like this:
+.nf
+"#!/usr/bin/csharp" 
+Console.WriteLine ("Hello, World");
+.fi
+.SH OPTIONS
+The commands accept all of the commands that are available to the 
+.I mcs
+command, so you can reference assemblies, specify paths, language
+level and so on from the command line.   In addition, the following
+command line options are supported:
+.TP 
+.I "\-\-attach"
+This is an advanced option and should only be used if you have a deep
+understanding of multi-threading.     This option is availble on the 
+.I csharp
+command and allows the compiler to be injected into other processes.
+This is done by injecting the C# shell in a separate thread that runs
+concurrently with your application.  This means that you must take
+special measures to avoid crashing the target application while using
+it.  For example, you might have to take the proper locks before
+issuing any commands that might affect the target process state, or
+sending commands through a method dispatcher.     
+.TP 
+.I "\-e" EXPRESSION
+This will evaluate the specified C# EXPRESSION and exit
 .SH OPERATION
 Once you launch the csharp command, you will be greeted with the
 interactive prompt:
@@ -88,8 +128,9 @@ csharp>
 .fi
 .PP
 A few datatypes are handled specially by the C# interactive shell like
-arrays, System.Collections.Hashtable and are rendered specially
-instead of just using ToString ():
+arrays, System.Collections.Hashtable, objects that implement
+System.Collections.IEnumerable and IDictionary and are rendered
+specially instead of just using ToString ():
 .PP
 .nf
 csharp> var pages = new Hashtable () { 
@@ -99,7 +140,6 @@ csharp> pages;
 {{ "Mono", "http://www.mono-project.com/" }, { "Linux", "http://kernel.org" }}
 .fi
 .PP
-.PP
 It is possible to use LINQ directly in the C# interactive shell since
 the System.Linq namespace has been imported at startup.   The
 following sample gets a list of all the files that have not been
@@ -119,14 +159,23 @@ You can of course print the results in a single statement as well:
 .nf
 csharp> using System.IO;
 csharp> var last_week = DateTime.Now - TimeSpan.FromDays (7);
-csharp> foreach (var old from f in Directory.GetFiles ("/tmp") 
+csharp> from f in Directory.GetFiles ("/tmp") 
       >   let fi = new FileInfo (f) 
-      >   where fi.LastAccessTime < LastWeek select f) 
-      >     Console.WriteLine (old);
+      >   where fi.LastAccessTime < last_week select f;
 [...]
 csharp>
 .fi
 .PP
+LINQ and its functional foundation produce on-demand code for
+IEnumerable return values.  For instance, the return value from a
+using `from' is an IEnumerable that is evaluated on demand.   The
+automatic rendering of IEnumerables on the command line will trigger
+the IEnumerable pipeline to execute at that point instead of having
+its execution delayed until a later point.
+.PP
+If you want to avoid having the IEnumerable rendered at this point,
+simply assign the value to a variable.
+.PP
 Unlike compiled C#, the type of a variable can be changed if a new
 declaration is entered, for example:
 .PP
@@ -170,11 +219,12 @@ csharp>
 .SH INTERACTIVE EDITING
 The C# interactive shell contains a line-editor that provides a more
 advanced command line editing functionality than the operating system
-provides.     
+provides.   These are available in the command line version, the GUI
+versions uses the standard Gtk# key bindings.
 .PP
 The command set is similar to many other applications (cursor keys)
 and incorporates some of the Emacs commands for editing as well as a
-history mechanism to 
+history mechanism too.
 .PP
 .PP
 The following keyboard input is supported:
@@ -197,7 +247,7 @@ line in the history.
 .TP
 .I Down Arrow Key, Control-n
 Moves forward in the history, replaces the current line with the next
-lien in the history.
+line in the history.
 .TP
 .I Return
 Executes the current line if the statement or expression is complete,
@@ -231,12 +281,19 @@ This is the quote character.   It allows the user to enter
 control-characters that are otherwise taken by the command editing
 facility.   Press Control-Q followed by the character you want to
 insert, and it will be inserted verbatim into the command line. 
+.TP
+.I Control-D
+Terminates the program.   This terminates the input for the program.
 .SH STATIC PROPERTIES AND METHODS
 Since the methods and properties of the base class from where the
 statements and expressions are executed are static, they can be
 invoked directly from the shell.   These are the available properties
 and methods:
 .TP
+.I void LoadAssembly(string assembly)
+Loads the given assembly.   This is equivalent to passing the compiler
+the -r: flag with the specified string. 
+.TP
 .I void LoadPackage(string package)
 Imports the package specified.   This is equivalent to invoking the
 compiler with the -pkg: flag with the specified string.
@@ -254,13 +311,40 @@ previous variable declarations, this is different than C# when
 compiled.   
 .I void ShowUsing()
 Displays all the using statements in effect.
+.I TimeSpan Time (Action a)
+Handy routine to time the time that some code takes to execute.   The
+parameter is an Action delegate, and the return value is a TimeSpan.
+For example:
+.PP
+.nf
+csharp> Time (() => { for (int i = 0; i < 5; i++) Console.WriteLine (i);});
+0
+1
+2
+3
+4
+00:00:00.0043230
+csharp>
+.fi
+.PP
+The return value is a TimeSpan, that you can store in a variable for
+benchmarking purposes. 
+.SH GUI METHODS AND PROPERTIES
+In addition to the methods and properties available in the console
+version there are a handful of extra properties available on the GUI
+version.   For example a "PaneContainer" Gtk.Container is exposed that
+you can use to host Gtk# widgets while prototyping or the "MainWindow"
+property that gives you access to the current toplevel window. 
 .SH STARTUP FILES
-The C# shell will load all the C# script files and Mono assemblies
-located in the ~/.config/csharp directory on Unix.  C# script files
-are files that have the extension .cs and they should only contain
-statements and expressions, they can not contain full class
-definitions (at least not as of Mono 2.0).   Full class definitions
-should be compiled into dlls and stored in that directory.
+The C# shell will load all the Mono assemblies and C# script files
+located in the ~/.config/csharp directory on Unix.  The assemblies are
+loaded before the source files are loaded. 
+.PP
+C# script files are files
+that have the extension .cs and they should only contain statements
+and expressions, they can not contain full class definitions (at least
+not as of Mono 2.0).  Full class definitions should be compiled into
+dlls and stored in that directory.
 .SH AUTHORS
 The Mono C# Compiler was written by Miguel de Icaza, Ravi Pratap,
 Martin Baulig, Marek Safar and Raja Harinath.  The development was
@@ -274,9 +358,9 @@ gmcs(1), mcs(1), mdb(1), mono(1), pkg-config(1)
 .SH BUGS
 To report bugs in the compiler, you must file them on our bug tracking
 system, at:
-http://www.mono-project.com/Bugs 
+http://www.mono-project.com/community/bugs/
 .SH MAILING LIST
-The Mono Mailing lists are listed at http://www.mono-project.com/Mailing_Lists
+The Mono Mailing lists are listed at http://www.mono-project.com/community/help/mailing-lists/
 .SH MORE INFORMATION
 The Mono C# compiler was developed by Novell, Inc
 (http://www.novell.com, http) and is based on the
@@ -284,5 +368,5 @@ ECMA C# language standard available here:
 http://www.ecma.ch/ecma1/STAND/ecma-334.htm
 .PP
 The home page for the Mono C# compiler is at
-http://www.mono-project.com/CSharp_Compiler  information about the
-interactive mode for C# is available in http://mono-project.com/CsharpRepl
+http://www.mono-project.com/docs/about-mono/languages/csharp/ information about the
+interactive mode for C# is available in http://mono-project.com/docs/tools+libraries/tools/repl/