Rickard Nilsson

  • Blog
  • Archive
  • About
  • Contact
Sign in

Welcome to rickardnilsson.net

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.

Follow @rickardn

Top Posts

  • Applying stylesheets dynamically with jQuery
  • ASP.NET MVC 2 Framework and Unity 2.0 Dependency Injection Container
  • Code Kata Cast
  • Isolate your code from ASP.NET with Moles Isolation Framework
  • ReSharper User tip #2: Refactor rename namespace
  • Dependency injection in ASP.NET MVC with Unity IoC Container

Categories

  • .NET
  • Agile
  • ASP.NET 2.0
  • ASP.NET 3.5
  • ASP.NET 4
  • ASP.NET MVC
  • BlogEngine.NET
  • C# 2.0
  • C# 3.0
  • C# 4.0
  • Continuous Integration
  • CSS
  • Design by Contract
  • Design Patterns
  • iPhone
  • JavaScript
  • Kata
  • Moles
  • Open source
  • Personal
  • Review
  • Social media
  • Software development
  • TDD
  • Testing
  • Umbraco
  • Unit testing
  • Unity
  • User tip
  • Web development

Five most recent posts

  • C# REPL and Interactive interpreter
  • TDD Kata 2 - Interaction based testing
  • Reflections from day 3 - Umbraco Codegarden 11 in Copenhagen
  • Reflections from day 2 - Umbraco Codegarden 11 in Copenhagen
  • Reflections from day 1 - Umbraco Codegarden 11 in Copenhagen

Tag cloud

  • agile
  • blogengine.net
  • c#
  • code kata
  • codegarden11
  • continuous integration
  • css
  • dependency injection
  • fakes
  • iso 8601
  • javascript
  • jquery
  • refactoring
  • resharper
  • tdd
  • testing
  • umbraco
  • unit test

C# REPL and Interactive interpreter

Sunday, 1 January 2012 15:20 by rickard

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

Download installer | Wiki | Source | Report an Issue

Usage

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
 
> 

Features

Support includes, but does not stop at:

Literal expressions:

> 1 + 2
3
> 2 * 4
8
> "hello, world"
"hello, world"

Semicolon is optional:

> 1 + 2
3
> 1 + 2;
3

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
[1,2,3]
> var map = new Dictionary<int, string> {{1,"foo"},{2,"bar"}}
> map
[[1, "foo"],[2, "bar"]]

Method declarations:

> int Foo() { return 1; }
> Foo()
1

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;
>    }
> }
> var foo = new Foo()
> foo.AddOne(1)
2

Using statements:

> new ArrayList {1}
The type or namespace name 'ArrayList' could not be found
> using System.Collections
> new ArrayList {1}
[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 { 
NameTransform = ZipNameTransform { TrimPrefix = null },  
Setting = LastWriteTime,  FixedDateTime = 2012-01-01 12:36:13,  
GetAttributes = -1,  SetAttributes = 0,  IsUnicodeText = False },  
UseZip64 = Dynamic,  RestoreDateTimeOnExtract = False,  
RestoreAttributesOnExtract = False }
Tags:   csrepl repl interactive interpreter console trycsharp
Categories:   .NET | C# 4.0 | Software development | Open source
Actions:  
 
Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© 2008-2011 rickardnilsson.net
Creative Commons-licens