Did this ever occur to you?

You wanted to write several lines of C# code to clarify some syntax or parameter format, or you needed a one-time program to process log files. You started Visual Studio 2005/2008, created a new console application project, wrote several lines of code, then build, run, and finally got the result.  What if the answer you wanted to know is simply whether decimal.ToString("N2") will return the correct formatted number?  How long have you been waited before writing the first line of code?  After you got the answer, would you spend several seconds to delete the *.csproj, *.cs files?

Quite often I felt that I spent 60% of my time on waiting for Visual Studio initialization and project operation, 40% on coding and execution, and it ended up left a whole bunch of unnessary files in my workspace. This is not efficient at all!  In these cases, Visual Studio is too heavy, but coding with notepad and csc.exe is too lousy.  What I really need is a light-weight IDE than can startup in one second and allows me to edit the code directly and run it with one click.  So, here is my Mini C# Coding Lab.

Mini C# Lab is a .NET 2.0 winform application with single 13KB exe file. As you see, the UI is quite simple and easy to use.  Write the code on the code editor, then click "Run" button to check the result.  The colorful formatting effect is based on Manoli's CSharpFormat. I use an easy, stupid but inefficient way to implement the formatting, so it's not real time. The RichTextEditor refreshes every time when you press after up/down/enter key, so don't try to edit a very long code. (It's only for "mini", right?)

The code is running in another thread, so you can stop it if it hang or the time is longer than you expected.  Mini C# Lab also provide simple open and save function, so you can keep your source code in single .cs file for furture use.

OK, that's all, try it and feel free to send me feedback

Download Ver 1.0

【中文摘要】

你是否有這樣的經驗?

只想寫兩行Code,試試某個語法的效果,或做個一次性轉檔。為了這幾行Code,你得開啟Visual Studio,等待它啟動,建一個專案,寫兩行Code,建置、執行、搞定,然後留下一整個專案資料夾跟一堆不會再用第二次的檔案。算一算,寫Code只花了40%的時間,卻花了60%的時間等待Visual Studio的啟動及建立專案上,更甭提這個"免洗"專案所留下的一堆殘檔。

我以前會偷用Word或Excel的巨集功能用來測試VB語法,試完後選擇不存檔,整個處理速度比啟動VB6來得快,且什麼都不留下。Office到了2007,也還不能在VBA裡寫.NET,我一直為在.NET方面找不到類以的替代方案而惋惜。

那麼... 自己寫一個吧!

Mini C# Lab是一個.NET 2.0 WinForm程式,只有一個13KB的獨立執行檔,免安裝,直接執行即可。你可以用上面的編輯視窗直輸入寫C#程式,利用Console輸出結果。編輯欄位我用了Manoli's CSharpFormat標出顏色,不過用的是簡單但笨拙的做法,一整行寫完後才會更新,而且,由於它每次整段程式都要重新顯示,不適合太長的程式碼。(記住,我本來只是想"Mini"而已呀!)

程式碼在另一個Thread執行,所以執行過程可以Cancel;另外,你也可以將程式碼儲存成.cs供下回再讀取應用,比Visual Studio的Project模型簡便許多。

有需要的朋友可以試試看,想到什麼建議再反應給我吧!


Comments

# by sholfen

Good!!有這個就方便多了。

# by ffmm

這位大大您是用 CodeDom 來處理的嗎? Compile to assembly on-the-fly

# by River

一個小建議 ctrl-x 能不能變成 剪下呢?? 常常會不自主的按到

# by Rex

喔! 開始寫工具給大家用囉!! 加油!! ^^

# by chhuang

剛剛試玩了一下... 請問 Class 一定要寫 CSharpLab?? 然後一定要靜態方法一定是 Test() ?? 不能有其他的名稱?

# by chhuang

如果有自動縮版就好了... 剛剛練習拿來寫簡單的 linq 查詢...但是目前好像不支援... (有加上using System; 與 using System.Linq;)

# by Jeffrey

to ffmm, 你猜對了, 是超酷的CodeDom沒錯。 to River, 支援剪下貼上是不錯的主意,之後會加上 to chhunag, 小工具寫死了會去Call CSharpLab.Test()當成進入點以求單純,我原本的想法是這只是小處需要配合,干擾不致太大。至於自動縮排,看起來工程不小,呵... 我先記在紙上(認真抄狀),現階段我是用Tab鍵手動縮排。 Mini C# Lab 1.0還不能額外的Reference其他DLL(例如: System.Data.OracleClient、System.Linq),不過這個功能有在我的計畫中。 to sholfen, rex, 寫潛盾機(由來: http://tinyurl.com/6hx76k)一向是我的"壞習慣", 喜歡到處Sow給別人用則是我的另一個"壞習慣",哈!

# by Ken

如果可以 default C# code 那個 textbox 裡面的 text, 或者是 load a preset cs file on startup, 那就更理想了... 這樣連最基本的 class structure 都不用打 ... 我好像太懶了

# by Julian

套大陸人常說的「這個小東西真是棒的不得了」 真的很方便去測試一些物件、語法的 使用後有小小的建意,如果 public class CSharpLab { public static void Test() { 是一定要寫,那改由程式自行產生 而輸入框直接寫入要測試的程式 for (int i = 0; i < 20; i++) { Thread.Sleep(500); Console.Write("Hello, World! "); } 至於namespace由另外一個框框填入 using System; using System.IO; using System.Threading; 小小建議 :p (Ctrl + X 真的蠻容易中招的)

# by Jeffrey

to Ken, 按選單File/New就可以預載入我圖例中的cs,整個主架構就有了,餘下的只要把中間的邏輯改成自己的就可以了。(忘了提這點,好像有些人都沒發現) 不過,開啟時自動載入是好主意。 to Julian, 當初有考慮過你說的做法,就是只開放中間的地方寫Code,後來想到,有可能我會需要獨立出一些method,所以還是開放整個cs,彈性較大。那個public class CSharpLab與public static void Test()原本的想法是File/New的時候就會自動產生,不過說明得不夠清楚,好像害不少人白打了一堆字,真是不好意思。 的確,大家一提醒才發現,Ctrl-X==Exit的設計真是一整個糟,下個版本會改掉。

# by icools

哈還不賴, 有下有推阿

# by Ken

啊, 我怎麼沒有發現... 我還自己寫了一個 template 來 load 說... 一整個傻子 謝謝喔, 很 handy! 不過 "Ctrl+X"+1

# by 毛豆

請問有VB.net的版本嗎?

# by elleryq

感覺跟 SnippetCompiler 很類似 下載來試試~ :)

# by kennyshu

我都是用這個 LINQPad 網址:http://www.linqpad.net/ 可以寫C#, SQL和LINQ,也是單一檔案,不過大很多。程式最奇特的地方是會自己upgrade,更新之後也還是一個檔案,厲害!

Post a comment