rickardnilsson.net is a weblog and the online home of web developer and father of three, Rickard Nilsson... More
Rickard blogs about creating software solutions using ASP.NET and agile practices.
This blog post introduces CSRepl, the C# REPL and interactive interpreter which I have founded on BitBucket. REPL stands for Read-eval-print loop and is a simple, interactive computer programming environment. It can be used to evaluate C# expressions and statements on the flight as well as creating types (classes, stucts, enums).
CSRepl can conveniently be used to quickly explore .NET Framework classes and APIs as well as third party assemblies.
Download
Download installer | Wiki | Source | Report an Issue
CSRepl is implemented as a windows console application and to use it when installed, you simply start it with the csrepl command from the command line:
C:\Program Files (x86)\CSRepl\>csrepl
CSRepl 1.0 Interactive build 1.0.4383.22797
Copyright (c) trycsharp.org. All Rights Reserved.
For help type Help
>
Support includes, but does not stop at:
Literal expressions:
> 1 + 2
3
> 2 * 4
8
> "hello, world"
"hello, world"
Semicolon is optional:
> 1 + 2;
Sequence of statements:
> var x = 1
> x
1
> x = 2
2
Collections:
> new[] {1,2,3}
[1,2,3]
> var list = new List<int> {1,2,3}
> list
> var map = new Dictionary<int, string> {{1,"foo"},{2,"bar"}}
> map
[[1, "foo"],[2, "bar"]]
Method declarations:
> int Foo() { return 1; }
> Foo()
Type declarations:
> class Foo { public string Bar() { return "Bar"; } }
> var foo = new Foo()
> foo.Bar()
"Bar"
Multi line statements:
> class Foo
> {
> public int AddOne(int v)
> return v + 1;
> }
> foo.AddOne(1)
Using statements:
> new ArrayList {1}
The type or namespace name 'ArrayList' could not be found
> using System.Collections
[1]
Formatting of complex types:
> class Foo { public string Bar { get; set; } }
> var foo = new Foo { Bar = "Hello" }
> foo
Foo { Bar = "Hello" }
> var anonymous = new { X = 1, Y = "foo" }
> anonymous
{ X = 1, Y = foo }
> var xml = new XmlDocument();
> xml.LoadXml("<foo bar=\"baz\" />")
> xml
<foo bar="baz" />
Load external assemlies:
> LoadAssembly("ICSharpCode.SharpZipLib.dll")
> using ICSharpCode.SharpZipLib.Zip
> new FastZip()
FastZip { CreateEmptyDirectories = False, Password = null,
NameTransform = ZipNameTransform { TrimPrefix = null },
EntryFactory = ZipEntryFactory {
Setting = LastWriteTime, FixedDateTime = 2012-01-01 12:36:13,
GetAttributes = -1, SetAttributes = 0, IsUnicodeText = False },
UseZip64 = Dynamic, RestoreDateTimeOnExtract = False,
RestoreAttributesOnExtract = False }