Demo: Exec-Inline, an Add-in that executes the currently selected code, immediately
secretGeek .:dot Nuts about dot Net:.
home .: about .: sign up .: sitemap .: secretGeek RSS

Demo: Exec-Inline, an Add-in that executes the currently selected code, immediately

Execute the code immediately under the cursor

You're in Visual Studio (2003 in this case)

  1. Highlight the code you want to run.
  2. Press the 'exec inline' button on the toolbar.
  3. The code is compiled and executed in its own little assembly

All credit goes to these four places:

Code compilation retyped from jconwell's Dot Net Script Project at CodeProject.

Wrapper around compilation retyped from dstang2000's DynamicCompileAndRun project.

Help with writing a VS Add-in: Scott Swigart, PasteAs Visual Basic Add-in

And help with getting the currently selected text from the IDE, retyped from Kevin McFarlane's VS Csharp Macros page.

I deliberately re-typed, rather than copying and pasting their code, so that I'd have to really look at what was going on in every place.

(continues with 'how does it work')

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:

Neat tool.
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:


Imports Microsoft.VisualBasic
Imports System
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Data
Imports System.Threading
Imports System.Xml
Imports System.Collections
Imports System.Diagnostics
Public Class Fred
  Public Sub New()
    MessageBox.Show("Hello")
  End Sub
  Private Shared Sub Main()
    Dim f As New Fred()
  End Sub
End Class



'Jim Mc' on Fri, 20 Oct 2006 05:32:12 GMT, sez:

hi,

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

thanks,
Jim



'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






name


website (optional)


enter the word:
 

comment (HTML not allowed)


All viewpoints welcome. But the right to delete any post for any reason is reserved. Don't make me do it. Comments may be republished, emailed to your loved ones or printed and used as toilet paper. Who reads this legal bit anyhow?

TimeSnapper is a life analysis system that stores and plays-back your computer use. It makes timesheet recording a breeze, helps you recover lost work and shows you how to sharpen your act.

TimeSnapper won last year's Developer Competition at Larkware.com, and is used by over 10,000 people.

Articles

Do they store the code for TFS in TFS? Do they store the code for TFS in TFS?
Sudden TimeSnapper Discount! Sudden TimeSnapper Discount!
How Can Microsoft Beat Google? How Can Microsoft Beat Google?
TimeSnapper 3.1: Attack of the the Red/Green Stripes TimeSnapper 3.1: Attack of the the Red/Green Stripes
21 tools used in our MicroISV 21 tools used in our MicroISV
Lost Treasures of the DOS World: tree! Lost Treasures of the DOS World: tree!
The Virtual Machine Machine and the Virtual Virtual Machine The Virtual Machine Machine and the Virtual Virtual Machine
Should Linq To Sql Go Should Linq To Sql Go "Open Source"?
Redux: New Synchronisation Idea Overlooked By Microsoft Redux: New Synchronisation Idea Overlooked By Microsoft
New Synchronisation Idea Overlooked By Microsoft Live team New Synchronisation Idea Overlooked By Microsoft Live team
Visual Studio UX Taskforce, Office UX Taskforce... etc. Visual Studio UX Taskforce, Office UX Taskforce... etc.
How to be Jeff Atwood How to be Jeff Atwood

Archives .: secretGeek :: Complete Archives :.
25 steps for building a Micro-ISV 25 steps for building a Micro-ISV
3 minute guides -- babysteps in new technologies: powershell, JSON, watir, F# 3 Minute Guide Series
Top 10 SecretGeek articles Top 10 SecretGeek articles

Downloads

TimeSnapper -- Automated Screenshot Journal TimeSnapper.com    
Version 3.1: instant productivity profiles

ShinyPower (help with Powershell) ShinyPower
Now at CodePlex

Next Action NextAction
Managing the top of your mind



[powered by Google] 


Thai Erawan, Brisbane Restaurant, delicious thai food in paddington Thai Erawan, Brisbane Restaurant
World's Simplest Code Generator (html edition) World's Simplest Code Generator
Gradient Maker -- a tool for making background images that blend from one colour to another. Forget photoshop, this is the bomb. Gradient Maker
How to be depressed How to be depressed
You are not inadequate.



Recommended Reading

The Best Software Writing I
The Business Of Software (Eric Sink)

Recommended blogs

Jeff Atwood
Reginald Braithwaite
Joseph Cooney
Phil Haack
Scott Hanselman
Julia Lerman
Joel Pobar
Eric Sink
Joel Spolsky
Des Traynor

Aggregated Links

programming.reddit.com
dzone
dot net kicks

Human Link Machines

interesting finds
a continuous learner's weblog
arjan's world
n links today
new and notable
morning coffee
learning .net
weekly link post
(my del.icio.us account)

LinkedIn profile
 
home .: about .: sign up .: sitemap .: secretGeek RSS .: © Leon Bambrick 2006 .: privacy

home .: about .: sign up .: sitemap .: RSS .: © Leon Bambrick 2006 .: privacy