Rickard Nilsson on crafting software | rickardnilsson.net Rickard Nilsson is a software architect, developer, craftsman, agile enthusiast, and father of three. Rickard blogs about crafting software using .NET http://www.rickardnilsson.net/ http://www.rssboard.org/rss-specification BlogEngine.NET 2.9.1.0 en-US http://www.rickardnilsson.net/opml.axd http://feeds.feedburner.com/RickardNilsson Rickard Nilsson Rickard Nilsson on crafting software | rickardnilsson.net 0.000000 0.000000 Introducing Consolas - a console application framework for .NET

consolas-iconI build small console applications all the time just to try something new or make small tools, like for integration purposes. This post introduces a new, light weight, framework for building anything from small throw aways to larger, powerful console applications in .NET. In most project templates there’s some form of guidance and support. For ASP.NET we have MVC framework and for windows applications, we have WPF or Win RT. If you create a new console application you only get an empty main method and that’s it.

I’m calling it Consolas and I’ve designed it around a few core principles.

  • Small fingerprint
  • Convention over configuration
  • Testable
  • Fast

How to get it?

Simply create a new Console Application and install the Nuget package Consolas or run the following command in the Package Manager Console

   1: PM> Install-Package Consolas

That will add the follow files to your project:

Files added by Consolas

What you need to do yourself to get going is to edit the Program.cs file:

   1: using Consolas.Core;
   2:  
   3: namespace ConsolasApplication
   4: {
   5:     class Program : ConsoleApp
   6:     {
   7:         static void Main(string[] args)
   8:         {
   9:             Match(args);
  10:         }
  11:     }
  12: }

Now Consolas will start to match program arguments to POCO classes in your project, e.g. HelpArgs added by the Nuget package. Thus, running the program from the console with the argument –help will execute the Execute method in the HelpCommand class.

   1: C:\...> program.exe -Help
   2: Using: program.exe ...

In the same manor, you can start building your console application by defining classes which represent the possible arguments for a command, and the corresponding command classes them selves. By convention any class that has properties matching program arguments, Consolas will try to match it to a command. The argument class is matched by looking for commands which takes the argument class as parameter in the command’s execute method. Here is the general convention:

matching args to command by convention

Looks interesting? Be sure to check out the GitHub project site, the Consolas tag where more articles will be posted.

http://www.rickardnilsson.net/post/consolas-a-console-application-framework-for-dot-net rickard@rickardnilsson.net http://www.rickardnilsson.net/post/consolas-a-console-application-framework-for-dot-net#comment http://www.rickardnilsson.net/post.aspx?id=62f560b7-1935-4a4b-9ffc-62662b89ccf1 Sat, 08 Mar 2014 19:29:24 +0200 Open source Software development rickard http://www.rickardnilsson.net/pingback.axd http://www.rickardnilsson.net/post.aspx?id=62f560b7-1935-4a4b-9ffc-62662b89ccf1 0 http://www.rickardnilsson.net/trackback.axd?id=62f560b7-1935-4a4b-9ffc-62662b89ccf1 http://www.rickardnilsson.net/post/consolas-a-console-application-framework-for-dot-net#comment http://www.rickardnilsson.net/syndication.axd?post=62f560b7-1935-4a4b-9ffc-62662b89ccf1
How to unit test your database code when using ServiceStack OrmLite

servicestackI’ve been working extensively with ServiceStack lately and I really like what they’ve done. As it contains the full stack for building HTTP based services from text serializers to development tools to a micro ORM it’s very easy to fall into the pit of success. I don’t mind picking and choosing these things for my self, however it’s nice that is doesn’t require any brain power making choices. Plus you can always be assured that the tools you get in the box is quick to get started with, and has all the performance you’ll ever need. They might be too simplistic for your needs but then it’s nice to know that its usually very simple to replace them with something else.

Let me tell you a story.

I was cruising along doing my thing, test-driving my code and was feeling pretty good about myself. I was hitting a very high code coverage as I was only writing a little bit of test code, a little bit of production code, and refactored as I went along. Now, I hit a pain point which showed itself to be very difficult to get under test. It was the few lines where I actually called the database through OrmLite’s extension methods.

OrmLite is a micro ORM and is part of the basic ServiceStack package. It is a set of extension methods on top of System.Data.IDbConnection which makes it very easy to use at the same time giving you direct access to the underlying APIs. It consists of operations like Insert, Update, Select etc. and is really easy to get started with.

Anyway, as OrmLite is only extension methods on IDbConnection I though it’d be simple as cake to fake it out such that I could get my database calls under test as well.

Turns out it was way more difficult than I had anticipated. After a little while I gave up and left a total of four lines uncovered (one line per entity).

The other day I was looking through the ServiceStack documentation after something totally unrelated and stopped at a couple of lines that caught my attention.

// Use in-memory Sqlite DB instead
var dbFactory = new OrmLiteConnectionFactory(
    ":memory:", false, SqliteOrmLiteDialectProvider.Instance);

 

So, it was possible to use an in memory database instance instead of the SQL Server provider I was using in production. Very interesting. Could I utilize this in my unit tests to get that last mile?

Lets see. I quickly wrote a little unit test to try it out.

   1: [TestClass]
   2: public class EntityRepositoryTests
   3: {
   4:     Entity expectedEntity;
   5:  
   6:     [TestMethod]
   7:     public void GetAll_All_ReturnsAllFromDatabase()
   8:     {
   9:         var dbFactory = new OrmLiteConnectionFactory(
  10:             connectionString: ":memory:",
  11:             autoDisposeConnection: false,
  12:             dialectProvider: SqliteOrmLiteDialectProvider.Instance);
  13:  
  14:         using (var db = dbFactory.OpenDbConnection())
  15:         {
  16:             db.CreateTable();
  17:             expectedEntity = new Entity
  18:             {
  19:                 Id = 1,
  20:                 Name = "foo"
  21:             };
  22:             db.Insert(expectedEntity);
  23:         }
  24:  
  25:         var repository = new EntityRepository(dbFactory);
  26:  
  27:         var result = repository.GetAll().ToList();
  28:             
  29:         Assert.That(result, Is.EqualTo(new [] { expectedEntity }));
  30:     }
  31: }

 

Sqlite is not included in the standard ServiceStack package, however it’s simply a matter of running a command in the Nuget Package Manager Console:

   1: PM> Install-Package ServiceStack.OrmLite.Sqlite32

for the test project and SqliteOrmLiteDialectProvider lights up.

When this was done NCrunch automagically picked it up and everything turned green immediately. Nice!

 

Running the test with MSTest was a little trickier as it turned out. Sqlite drops an interop dll in the test project as a resource which MSTest couldn’t pick up. To get that to work I needed to add the dll as a deployment file in the local test settings. When I did that, the whole thing even ran in the continuous integration build in TeamCity.

Awesome day at work. Hope you’ve found this tip useful. Cheers!

http://www.rickardnilsson.net/post/how-to-unit-test-your-database-code-when-using-servicestack-ormlite rickard@rickardnilsson.net http://www.rickardnilsson.net/post/how-to-unit-test-your-database-code-when-using-servicestack-ormlite#comment http://www.rickardnilsson.net/post.aspx?id=756e84fe-23d2-4093-b3c4-12e58561aacb Sat, 19 Jan 2013 01:11:00 +0200 Open source Software development Unit testing rickard http://www.rickardnilsson.net/pingback.axd http://www.rickardnilsson.net/post.aspx?id=756e84fe-23d2-4093-b3c4-12e58561aacb 5 http://www.rickardnilsson.net/trackback.axd?id=756e84fe-23d2-4093-b3c4-12e58561aacb http://www.rickardnilsson.net/post/how-to-unit-test-your-database-code-when-using-servicestack-ormlite#comment http://www.rickardnilsson.net/syndication.axd?post=756e84fe-23d2-4093-b3c4-12e58561aacb
Extract class - ReSharper Ninja tricks

This is part of a series of ReSharper Ninja ticks and workflows which I’ve picked up over the years. This particular one is brand new in ReSharper 7.

Extract class

Category: Refactoring

This is a new feature in ReSharper 7 and one that I and many with me has been missing for a long time. Previously when you had a class with too many responsibilities, you had to go through a lot of hoops with ReSharper to refactor the code into cohesive units, and it usually involved a few manual steps.

Now, in version 7, we have an option on the refactoring menu called Extract class which automate the procedure. You place the marker on a class member and hit Ctrl+Shift+R to bring up the refactoring menu, and choose Extract class. This gives you a dialog where you can pick which members should be extracted and ReSharper analyses dependencies between different members such that the code won’t brake after the refactoring.

Whats new in ReSharper 7

Checkout Hadi Hariri’s presentation on Extract Class at 07:28

http://www.rickardnilsson.net/post/extract-class-resharper-ninja-tricks rickard@rickardnilsson.net http://www.rickardnilsson.net/post/extract-class-resharper-ninja-tricks#comment http://www.rickardnilsson.net/post.aspx?id=07111d78-d9cf-4538-aaa9-de3265712822 Thu, 06 Sep 2012 06:46:00 +0200 User tip Software development rickard http://www.rickardnilsson.net/pingback.axd http://www.rickardnilsson.net/post.aspx?id=07111d78-d9cf-4538-aaa9-de3265712822 0 http://www.rickardnilsson.net/trackback.axd?id=07111d78-d9cf-4538-aaa9-de3265712822 http://www.rickardnilsson.net/post/extract-class-resharper-ninja-tricks#comment http://www.rickardnilsson.net/syndication.axd?post=07111d78-d9cf-4538-aaa9-de3265712822
ASP.NET MVC 3 Template with built in JavaScript and CSS merging and minification

asp-net-mvc-3In a previous post I described the importance of optimizing your web site resources and how you can do it using the open source tool Ajax Minifier. I’ve received a few questions about how to automate this process and now I want to share a ASP.NET MVC 3 template with the combining and minification built in as a post compile step.

Since my last post Ajax Minifier is now available as a NuGet package and is easily installed in your solution either via NuGet Package Manager or using the NuGet Package Manager Console command:

PM> Install-Package AjaxMin

However, to get the AjaxMin.exe you’ll have to download it manually from Codeplex. My MVC 3 template is build on a simple Internet Application MVC 3 template with Razor and HTML5 semantic markup. My additions to automate resource optimizations consists of the following:


After the web project is built a custom target is called:

<Import Project="$(MSBuildProjectDirectory)\AfterBuild.tasks" />
<Target Name="AfterBuild">
    <CallTarget Targets="Minify">CallTarget>
Target>


The after build target executes the AjaxMin executable:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <BuildLibPath>$(MSBuildProjectDirectory)\..\packagesBuildLibPath>
        <Ajaxmin>$(BuildLibPath)\AjaxMin.4.62.4618.15628\bin\Ajaxmin.exeAjaxmin>
    PropertyGroup>
    <Target Name="Minify">
        <Exec Command='"$(Ajaxmin)" -js -xml minify.js.xml -clobber' Condition="'$(Configuration)' == 'Release'" />
        <Exec Command='"$(Ajaxmin) -css -xml minify.css.xml -clobber' Condition="'$(Configuration)' == 'Release'" />
    Target>
Project>


The xml files minify.js.xml and minify.css.xml are used to define which resources should be merged together, minified and where to output the result.

<root>
  <output path="Scripts/Mvc3Application.min.js">
    <input path="Scripts/myplugin.js"/>
    <input path="Scripts/viewModel.js"/>
    <input path="Scripts/foobar.js"/>
  output>
root>


Download ASP.NET MVC Template (3,5MB)

Target: .NET 4.0

http://www.rickardnilsson.net/post/aspnet-mvc-3-template-with-built-in-javascript-and-css-merging-and-minification rickard@rickardnilsson.net http://www.rickardnilsson.net/post/aspnet-mvc-3-template-with-built-in-javascript-and-css-merging-and-minification#comment http://www.rickardnilsson.net/post.aspx?id=85f2c276-8483-434b-b8a2-6e976c6140f8 Mon, 03 Sep 2012 07:28:00 +0200 CSS JavaScript User tip Web development rickard http://www.rickardnilsson.net/pingback.axd http://www.rickardnilsson.net/post.aspx?id=85f2c276-8483-434b-b8a2-6e976c6140f8 1 http://www.rickardnilsson.net/trackback.axd?id=85f2c276-8483-434b-b8a2-6e976c6140f8 http://www.rickardnilsson.net/post/aspnet-mvc-3-template-with-built-in-javascript-and-css-merging-and-minification#comment http://www.rickardnilsson.net/syndication.axd?post=85f2c276-8483-434b-b8a2-6e976c6140f8
ReSharper Ninja tricks - Generate code from usage

I’ve been a heavy ReSharper user, fan, and addict since I first tried it back in 2007. Over the years I’ve developed the way I code leveraging the powerful productivity features of ReSharper and Visual Studio.

I present a series of my favorite Ninja tricks and workflows to inspire others to improve their skills and I encourage you to do the same, either in the comments section or elsewhere.

You can find this and other power tips with the ReSharper user tip tag 

Generate code from usage + Move to folder

Category: Workflow

Following test-driven development I often define my unwritten classes by first using it in a unit test. I then use Create class and Create method or property to generate the code from usage. As the class gets created in the same file as the unit test I use Move to folder to put the class in the production code assembly. Namespaces and using statements are fixed automatically.

 

Create class from usage
Place the marker on the class name in red and hit Alt+Enter

arrow-down

Create method from usage

Place the marker on the method name in red and hit Alt+Enter

arrow-down

Move to folder

Place the marker on the class name and hit Ctrl+R, O. Then pick the folder you want the class to move to.

http://www.rickardnilsson.net/post/generate-code-from-usage-resharper-ninja-tricks rickard@rickardnilsson.net http://www.rickardnilsson.net/post/generate-code-from-usage-resharper-ninja-tricks#comment http://www.rickardnilsson.net/post.aspx?id=bafc1fc4-a0a1-41f6-8dc7-93a8ed09c5f1 Tue, 28 Aug 2012 19:52:00 +0200 Software development User tip rickard http://www.rickardnilsson.net/pingback.axd http://www.rickardnilsson.net/post.aspx?id=bafc1fc4-a0a1-41f6-8dc7-93a8ed09c5f1 0 http://www.rickardnilsson.net/trackback.axd?id=bafc1fc4-a0a1-41f6-8dc7-93a8ed09c5f1 http://www.rickardnilsson.net/post/generate-code-from-usage-resharper-ninja-tricks#comment http://www.rickardnilsson.net/syndication.axd?post=bafc1fc4-a0a1-41f6-8dc7-93a8ed09c5f1
Unit testing continuously

ncrunch.net

The foundation for all solid professional software development in my opinion is good craftsmanship practices and the most important of them is unit testing. It used to be great debate and controversy about weather unit testing was worth it or not but the fact is, the jury is back and the verdict is final. Unit testing is a core software development practice which can be ignored no longer, for any reason.

Unit testing is a relatively old practice and what has become the definition of a good unit test through decades of practice is the following:

  • It’s automated
  • It’s repeatable
  • It’s easy to implement
  • Once its written it sticks around
  • Anyone can run it. Easily
  • It runs fast

Given this definition there are many ways to produce these unit tests that are so important, but what has proven to be the most efficient way to get them done is to iteratively write a test before you write the production code which should make the test pass. Thus, using test-driven development, not only do you get unit tests written such that you can prove that the application is working as expected, but with test-driven development you get so many other benefits. It’s really about thinking through what your application should do and designing it to be testable which inherently forces you to make it more decoupled and cohesive, two of the oldest software metrics of good design.

With a suite of unit tests in which you trust, you are much more comfortable doing can do ruthless refactoring. Without tests you can’t. Refactoring is one of the core practices of test-driven development, and it’s all about making changes to the code to keep it flexible in order to make it easier to change and maintain.

When we’re doing test-driven development properly we’re working in very short cycles of writing a little bit of test code, a little bit of production code, and then cleaning up after our selves as we go along. When you do this you want to make sure that all your old tests passes for every change you make as well as only the test case you’re working on is failing as expected. This leads to lots of overhead of clicking buttons in the IDE or pressing short cut keys over and over again. What you really want is a way to run all the tests automatically when ever anything changes. This is where continuous testing comes into play.

Continuous testing as a practice is actually what you do when you’re doing test-driven development properly, however the term has been claimed by a range of tools which was sprung out of the Ruby community. It provides tool support for automatically detecting when you save a code file and then running the entire unit test suite and report the result back to you. Consequently it somewhat changes the way you do test-driven development because you never need to think about running your tests again. You simply keep on coding, adding another test, implementing it and meanwhile the red light has lit up and switched to green again as you’ve made it pass.

It might seem like a subtle change but I’ve found that it really changes and improves the flow when I code, plus using a tool like NCrunch, as a side effect, I get so many other cool features like code coverage and pass or fail status next to every line of code (see the image at the top of the post). NCrunch takes advantage of all the cores in my machine and uses parallel execution to run the entire suite of tests every time. It optimizes the build such that only the modules that are impacted by the change are built and run first so I get immediate feedback plus the rest of the test suite is running behind the scenes for safety.

Continuous testing tools for .NET:

Disclaimer: This is my view on how software development should be practiced in a professional environment. It is my own opinion and do not represent my employer’s view in any way.

http://www.rickardnilsson.net/post/unit-testing-continuously rickard@rickardnilsson.net http://www.rickardnilsson.net/post/unit-testing-continuously#comment http://www.rickardnilsson.net/post.aspx?id=7f207a58-b889-4bad-a73f-aa7656dbff3a Mon, 20 Aug 2012 14:51:00 +0200 Software development Unit testing rickard http://www.rickardnilsson.net/pingback.axd http://www.rickardnilsson.net/post.aspx?id=7f207a58-b889-4bad-a73f-aa7656dbff3a 0 http://www.rickardnilsson.net/trackback.axd?id=7f207a58-b889-4bad-a73f-aa7656dbff3a http://www.rickardnilsson.net/post/unit-testing-continuously#comment http://www.rickardnilsson.net/syndication.axd?post=7f207a58-b889-4bad-a73f-aa7656dbff3a
How we practice Continuous Integration at Ninetech with TFS TV

I’ve previously blogged about how we practice Continuous Integration with TeamCity at Ninetech but some time has passed and now it is time for an update.

After an upgrade to TFS2010 we started to use its build system for some of our development projects but since many of them lacked automated testing the usage didn’t really take off. To change this, an internship project was started where students from Karlstad’s university would create some way to highlight the opportunity to get immediate feedback for team members as well as stake holders and other interested at our company.

The result of the project can be seen below. It is our TFS TV placed on the wall of our developer room such that all developers, as well as any one who passes by, can see the current status of our projects. It is a WPF app which cycles through all of our TFS build configurations, gathers the latest test data, goes to our web site and fetches the photo of the latest committer, and displays it all on the 42” plasma screen.

TFS TV


The effect we’re after is to raise the level of awareness and usage of continuous integration and automated testing by providing immediate feedback to all teams when something fails and as well as a quick way of keeping track of a project through some of its metrics.

As seen below no one can miss if a build is failing which makes everybody who commits to a project on the screen extra careful not to commit code which is untested or brakes the build in any way.

TFS TV Build failure


What’s next? As we’re using a mix of source control systems (TFS, Git, Hg, SVN) and continuous integration platforms (TFS, TeamCity) the plan is to support TeamCity as well and maybe find a way to release it into the wild. We’ll se what happens.

http://www.rickardnilsson.net/post/how-we-practice-continuous-integration-at-ninetech rickard@rickardnilsson.net http://www.rickardnilsson.net/post/how-we-practice-continuous-integration-at-ninetech#comment http://www.rickardnilsson.net/post.aspx?id=4c52d339-8aa4-4e8b-b818-69eca750f552 Sun, 15 Jul 2012 11:15:00 +0200 Continuous Integration Software development Unit testing rickard http://www.rickardnilsson.net/pingback.axd http://www.rickardnilsson.net/post.aspx?id=4c52d339-8aa4-4e8b-b818-69eca750f552 1 http://www.rickardnilsson.net/trackback.axd?id=4c52d339-8aa4-4e8b-b818-69eca750f552 http://www.rickardnilsson.net/post/how-we-practice-continuous-integration-at-ninetech#comment http://www.rickardnilsson.net/syndication.axd?post=4c52d339-8aa4-4e8b-b818-69eca750f552
My customized Son of Obsidian Visual Studio color scheme for ReSharper

Update! Download for Visual Studio 2012 and ReSharper 7!

Since I switched to the dark side I’ve made several tweeks and customizations to the Son of Obsidian scheme. I’m a heavy ReSharper user (i.e. addict) and ReSharper on its own extends and overrides some of the the highlighting and what not in Visual Studio, hence the original scheme looks a bit broken when turning on all the ReSharper features.

I’ve finally decided that is was time to publish my changes so if you’re into Son of Obsidian and ReSharper, this is for you:

son-of-obsidian

 
Download Son of Obsidian scheme for Visual Studio 2012
Download Son of Obsidian scheme for Visual Studio 2010

Enable enhanced syntax highlighting

To enable the enhanced syntax highlighting and color identifiers in ReSharper, go to the Options dialog and check both Color identifiers and Highlight color usages.

rsharper_settings

 

See how to change Visual Studio color scheme

http://www.rickardnilsson.net/post/son-of-obsidian-color-scheme-for-resharper rickard@rickardnilsson.net http://www.rickardnilsson.net/post/son-of-obsidian-color-scheme-for-resharper#comment http://www.rickardnilsson.net/post.aspx?id=c95935b3-4ca4-44cb-aaab-375a9aa19d99 Sun, 20 May 2012 20:41:00 +0200 Software development rickard http://www.rickardnilsson.net/pingback.axd http://www.rickardnilsson.net/post.aspx?id=c95935b3-4ca4-44cb-aaab-375a9aa19d99 22 http://www.rickardnilsson.net/trackback.axd?id=c95935b3-4ca4-44cb-aaab-375a9aa19d99 http://www.rickardnilsson.net/post/son-of-obsidian-color-scheme-for-resharper#comment http://www.rickardnilsson.net/syndication.axd?post=c95935b3-4ca4-44cb-aaab-375a9aa19d99
Teaching kids programming

I brought my son to work the other day and was suppose to show him what I do for a living. I wanted to introduce him to programing but he is only eleven years old and his native language is Swedish, unlike most programming languages.

To introduce him to the idea of programming, i.e. the way to think in terms of logic and structure, I searched for a visual programing language and found Kodu from Microsoft Research, which is made for creating games on PCs and the XBox 360.

kodu sensor wheel

Using Kodu I was able to introduce the basic concepts of sequence and flow of control in a very concrete way where the child with a click of a button could run the game and see the consequences of his programing.

Where as my son is only eleven this was maybe a little too early, or he simply lacked interest, however I was thinking what the next step would be? I found a couple of options.

SmallBasic has a user friendly development environment, event for children, and easy to understand guidance to get going.

Finally I thought of VB.NET with Visual Studio Express, which is kind of the way I started out myself, however, then it was Visual Basic 3 and the Internet wasn’t invented yet (well, almost).

http://www.rickardnilsson.net/post/teaching-kids-programming rickard@rickardnilsson.net http://www.rickardnilsson.net/post/teaching-kids-programming#comment http://www.rickardnilsson.net/post.aspx?id=3847de8d-272a-400b-9bae-5318c4aeba23 Fri, 18 May 2012 06:17:13 +0200 Software development Personal rickard http://www.rickardnilsson.net/pingback.axd http://www.rickardnilsson.net/post.aspx?id=3847de8d-272a-400b-9bae-5318c4aeba23 5 http://www.rickardnilsson.net/trackback.axd?id=3847de8d-272a-400b-9bae-5318c4aeba23 http://www.rickardnilsson.net/post/teaching-kids-programming#comment http://www.rickardnilsson.net/syndication.axd?post=3847de8d-272a-400b-9bae-5318c4aeba23
C# REPL and Interactive interpreter

bitbucket_2This 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 fly 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 }
http://www.rickardnilsson.net/post/csharp-repl-and-interactive-interpreter rickard@rickardnilsson.net http://www.rickardnilsson.net/post/csharp-repl-and-interactive-interpreter#comment http://www.rickardnilsson.net/post.aspx?id=d461e6f9-c588-4b81-8ff6-eb14e33c5872 Sun, 01 Jan 2012 15:20:06 +0200 .NET C# 4.0 Software development Open source rickard http://www.rickardnilsson.net/pingback.axd http://www.rickardnilsson.net/post.aspx?id=d461e6f9-c588-4b81-8ff6-eb14e33c5872 10 http://www.rickardnilsson.net/trackback.axd?id=d461e6f9-c588-4b81-8ff6-eb14e33c5872 http://www.rickardnilsson.net/post/csharp-repl-and-interactive-interpreter#comment http://www.rickardnilsson.net/syndication.axd?post=d461e6f9-c588-4b81-8ff6-eb14e33c5872