Sandboxing C# code within a bigger project
Hi Guys,
I often find myself in a situation, where I need to quickly test some small C# code, for example some Linq query - literally a few lines of code. Obviously I also need console to print something, but it has nothing to do with my current project.
What comes in mind naturally is a separate console-based application. But I don't want to leave my project, as this is really very small task. As stupid as it sounds, I often use online C# compiler for that (which is a bit pathetic). Is there any way I can compile a C# class with a main function and have access to console within a bigger non-console application? (I work within a Unity project)
I remember XCode had a feature like this with Swift, called it sandbox mode I think and it was fantastic. Do you have any brilliant idea for me?
Thanks :)
Please sign in to leave a comment.
I guess this forum is dead.. Zero replies in all new threads..
Hi!
Thank you for contacting us.
This forum is not dead, just a bit slow. :) Sorry about that.
Please, try C# Interactive. It allows running C# statements without having to wait for compilation. This means we can get immediate feedback on what a given expression will return.
Hope this helps! If you have any questions, please, let me know.
Hi Alexandra,
Thank you for your reply. I have played with C# interactive and I am not convinced. Can you help me a bit more?
I hate typing the code inside console directly, I would rather write in the editor and press "run" when I'm ready. So I created a separate C# class to keep my test methods there. But once I have my method ready for testing, I need to:
If I need to repeat this 20 times within 5 minutes (with some minor code tweaking) it gets annoying very quickly. Especially selecting the code with the mouse! So, to get to the point, is there a way to facilitate this? Fot example, I want to have a button that will run THIS method again (with or without compilation, I don't care)
Thanks,
Tom
Hi Tom!
Is the clean console is critical for you? For this, there is a Reset button in the Console toolbar, but there is no shortcut for this action.
There are two ways to execute code:
- Select a block of code in the editor and press Ctrl+\ or press Alt+Enter and then choose Send selection to C# interactive.
- Copy\paste\type any code directly to the console and press Enter.
To repeat any previous part of code, just set focus to the C# Interactive console and press Up\Down to choose the previous code and Enter to execute it again.
Hope this helps!