Rickard Nilsson

  • Blog
  • Archive
  • About
  • Contact

Welcome to rickardnilsson.net

Rickard Nilsson is a software architect, developer, craftsman, agile enthusiast, and father of three... More

Rickard blogs about crafting software using .NET tooling and solid, development practices.

Follow @rickardn

Top Posts

  • Applying stylesheets dynamically with jQuery
  • My customized Son of Obsidian Visual Studio color scheme for ReSharper
  • .NET Development with Visual Studio on MacBook Pro
  • Code Kata Cast
  • ReSharper User tip #2: Refactor rename namespace
  • Combining and minifying JavaScript and CSS files with Ajax Minifier
  • Dependency injection in ASP.NET MVC with Unity IoC Container
  • C# REPL and Interactive interpreter

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

  • How to unit test your database code when using ServiceStack OrmLite
  • Extract class - ReSharper Ninja tricks
  • ASP.NET MVC 3 Template with built in JavaScript and CSS merging and minification
  • ReSharper Ninja tricks - Generate code from usage
  • Unit testing continuously

Tag cloud

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

Recent comments

<< TDD Kata 2 - Interaction based testing | Teaching kids programming >>

C# REPL and Interactive interpreter

Sunday, 1 January 2012 15:20 by Rickard Nilsson

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("")
> xml
"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:  

Related posts

Prime Factors Kata in C#The Prime Factors Kata, initially sparked by the infamous Uncle Bob Martin, is about finding an arbi...Week and strong contracts in Design by Contact Answer to Fredrik Normén on Defensive programming and Design by Contract on a routine level...The Humble dialog v.2Update! Download source: TheHumbleDialog2.zip (29,96 kb) I've been working to get my head around th...
 
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