is an interactive C# shell that allows the user to enter and evaluate
C# statements and expressions from the command line. The regular
.Imcs
command line options can be used in this version of the compiler.
.PP
The
.Igsharp
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
.Icsharp
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
.SHOPTIONS
The commands accept all of the commands that are available to the
.Imcs
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
.Icsharp
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
.SHOPERATION
Once you launch the csharp command, you will be greeted with the
interactive prompt:
.PP
.nf
$ csharp
Mono C# Shell, type "help;" for help
Enter statements below.
csharp>
.fi
.PP
A number of namespaces are pre-defined with C# these include System,
System.Linq, System.Collections and System.Collections.Generic.
Unlike the compiled mode, it is possible to add new using statements
as you type code, for example:
.PP
.nf
csharp> new XmlDocument ();
<interactive>(1,6): error CS0246: The type or namespace name `XmlDocument' could not be found. Are you missing a using directive or an assembly reference?
csharp> using System.Xml;
csharp> new XmlDocument ();
System.Xml.XmlDocument
.fi
.PP
Every time a command is typed, the scope of that command is one of a
class that derives from the class Mono.CSharp.InteractiveBase. This
class defines a number of static properties and methods. To display
a list of available commands access the `help' property:
.nf
csharp> help;
"Static methods:
LoadPackage (pkg); - Loads the given Package (like -pkg:FILE)
[...]
ShowVars (); - Shows defined local variables.
ShowUsing (); - Show active using decltions.
help;
"
csharp>
.fi
.PP
When expressions are entered, the C# shell will display the result of
executing the expression:
.PP
.nf
csharp> Math.Sin (Math.PI/4);
0.707106781186547
csharp> 1+1;
2
csharp> "Hello, world".IndexOf (',');
5
.fi
.PP
The C# shell uses the ToString() method on the returned object to
display the object, this sometimes can be limiting since objects that
do not override the ToString() method will get the default behavior
from System.Object which is merely to display their type name:
.PP
.nf
csharp> var a = new XmlDocument ();
csharp> a;
System.Xml.Document
csharp> csharp> a.Name;
"#document"
csharp>
.fi
.PP
A few datatypes are handled specially by the C# interactive shell like
arrays, System.Collections.Hashtable, objects that implement
System.Collections.IEnumerable and IDictionary and are rendered