Demo: Exec-Inline, an Add-in that executes the currently selected code, immediately
How does it work?
The code you select gets wrapped inside it's own class (unless it contains a class of its own) and then an entry point is added to this class. A bunch of common imports (i.e. include) statements are added, just in case.
It's compiled using
System.CodeDom.Compiler which is remarkably easy to do.
If the code doesn't compile -- then I display a mini window, showing the generated code, and what compilation errors there were. This gives you a chance to alter the code and get it to work.
If there's a runtime exception, then I display the same window, along with the exception that occurred.
I don't have enough time to work on this project. So it's on the backburner, alongside ShinyPower Analyzer, WSCG v4, Crank, SimpleTests, and everything that isn't TimeSnapper or Advantech.
Writing this add-in was actual just a detour along the way toward writing a SimpleTests add-in, which I'm still kicking around in the back of my mind.
The steps and decisions involved in getting that puppy to fly are all too many.
Regarding exec immediate: Source code currently is VB only (since the PC i first developed it on didn't have C# installed). Once I've made it work for both languages, I'll post the project up.
'Snippet Compiler' on Thu, 19 Oct 2006 21:34:00 GMT, sez:
Check out Jeff Key's snippet compiler -- 3 years old now!
maybe when errors occur then snippet compiler could be launched with the generated code in there.
and when the snippet is done, it could be pasted over the top of the original selected text in visual studio.
'Dan F' on Thu, 19 Oct 2006 22:24:38 GMT, sez:
Dude! This feels like the old method of banging some code into the immediate window for days when you were having a brain fade, only it's better! I love it. Or, I'm pretty sure I'll love it, haven't actually tried it yet. This is going straight to the pool room though.
I think it's got a definite advantage over snippet compiler for some situations. Sometimes you just want to test a certain behaviour, a small snippet, etc. Being able to do that in mid flow without having to copy, paste into snippet compiler, test, copy, paste back into the IDE, will be ace.
'Dan F' on Thu, 19 Oct 2006 22:35:11 GMT, sez:
Am I having one of the aforementioned brain fade days, or is there no link to try this beast? Help a fellow downunderian out lb :)
'lb' on Thu, 19 Oct 2006 23:04:05 GMT, sez:
@Dan: code is winging its way to you now.
'Joshua Flanagan' on Fri, 20 Oct 2006 03:09:44 GMT, sez:
Another simliar solution to this and Snippet Compiler is the "Ad-hoc" test runner in the TestDriven.NET Add-in. Requires a little more overhead than yours (you have to make a void Foo() method to wrap the code you want to play with), but has the nice advantage of being able to interact with all of the other objects in your project.
'lb' on Fri, 20 Oct 2006 03:19:22 GMT, sez:
Yeh this tool works by wrapping the void Foo() around your code --
In the case of a simple 'MessageBox.Show("HelloWord")', this is the code that actually gets compiled:
Public Class Fred
Public Sub New()
Private Shared Sub Main()
Dim f As New Fred()
'Jim Mc' on Fri, 20 Oct 2006 05:32:12 GMT, sez:
i'm a long time reader, first time poster. great site!!
is there any chance I Could get a copy of the VB Source? This would be a very useful tool to have :o) (sorry, im impatient and wanted to try this)
i'm at (removed for privacy reasons)@Hotmail.com
'lb' on Thu, 26 Oct 2006 09:02:56 GMT, sez:
** BETA TESTERS NEEDED **
anyone else who's after the code to this one -- just write and ask for it:
leonbambrick at gmail dot com
'JIthendra' on Tue, 31 Oct 2006 03:41:39 GMT, sez:
Hi can I get a copy of this cool stuff.
'Ian' on Fri, 03 Nov 2006 01:28:08 GMT, sez:
could i please get a copy of the code??
(removed for privacy reasons) at hotmail.com
thanks!! great idea btw