“If your business depends on you, you don't own a business--you have a job. And it's the worst job in the world because you're working for a lunatic!”
by Michael E. Gerber The E-Myth (Revisited)

Snippet: Compiler

Here’s a little snippet (from a friend; thanks again, man!) that will allow you, out of the box, to compile and execute C# code from your SOS input. The results of that code are returned as your response. I’m sure all of the C# coders out there can appreciate this one. One (pretty big) added bonus is the fact that this snippet compiler is not bound to C#. It’s not even bound to .NET! Within the configuration file, there are settings that will allow you to specify your own compiler, switches, and base code.

Click here to download the snippet: Compiler

Sample Input:
String text = "Hello World!";
foreach(Char c in text)
   String format = "[{0}:{1}] ";
   String character = c.ToString();
   String ascii = ((Int32)c).ToString();
   Console.Write(format, character, ascii.PadLeft(3, ‘0’));

Sample Output:
[H:072] [e:101] [l:108] [l:108] [o:111] [ :032] [W:087] [o:111] [r:114] [l:108] [d:100] [!:033]

3 Responses to “Snippet: Compiler”

  • Apparently, my rebuild of this snippet is only working on Vista. I will correct and update as soon as possible. Sorry for the inconvenience.

    Thumb up Thumb down 0

  • Alrighty, then. Me and Michael got together on this one and made it do what it needed to… and then some! Now Compiler.sos has a better default base class, runs cleaner, and compiles your code into a snippet that can be used right after you build it with this.

    There is a snag, however. This discovery brought a GUI issue to light as well. After you build your new snippet, the snippet is dropped into the same directory that Compiler.sos is running from. This will cause the menus AND GUI TREE to rebuild themselves. When this happens, the GUI will not even notice that a snippet is no longer selected, so to make a change, you’ll need to copy your current input and click the snippet again (then paste, obviously). Then you can re-run Compiler.sos to “rebuild” the Temporary.sos that was generated.

    I have already corrected the issue in the GUI, but I will not be able to release it right away, so I thought the work-around would hold you over for a bit. Also, this does not effect “Screen -> Screen” or any other menu option, so building there works just fine.

    Thumb up Thumb down 0

  • Elizabeth S. – HOLY HELL! I was wondering who you would ask to take these for you. It’s alayws interesting to see which fellow photographer is picked by another photographer and I wouldn’t have gone with anyone else. Congrats on your engagement and these amazing images.

    Thumb up Thumb down 0

Leave a Reply

Get a free book about code review best practices.