Search code examples
c#vbaruntimeintellisensescripting-language

How to give user an equivalent Excel-VBA environment for my application in C#


I'd like to give user the opportunity to do its own report based on my class hierarchy (object in memory). A scripting language like VBA: Visual Basic for Application. Something that would be evaluated at runtime.

I'd like the user to be able to dynamically create its own report based on some available restricted objects marked with specific attributes only. Give user possibility to create macro where he have similar model as in VBA-Excel : Application/Workbook/WorkSheet/Range/... but with my specific selected objects instead.

Then, he would have been able to use intellisense and add its own functionality to its application.

Update: There is something very important that appears to me. The editor should be preferably part of the application itself in order for the script to know all the environment (namespace, objects, ...) it should interact with. Otherwise, having a scripting engine/editor in a separate process would force the application to be either a "single-instance" app or to create a tricky way to hook the script to a specific running application process.

Does it exists and how to plug it to a .net app?

4 solutions have been proposed:

  1. IronRuby
  2. CsScript
  3. WinWrap
  4. Windows Scripting Host (WSH)

I also found:

  1. ScriptCs
  2. RoslynPad
  3. Code Project - Anoop Madhusudanan article: C# as a Scripting Language in Your .NET Applications Using Roslyn

But I wonder which one could fits every needs (or most of them):

  1. Editor with Intellisense
  2. User have access the currently running process object model (Application as global and all its related objects accessed through application properties). Optional but very nice to have: not necessarily every public properties, only marked ones with specific attributes.
  3. Interactive environment enabling step by step, debugging, breakpoints, ...
  4. Editor/debugger Licensed for free redistribution
  5. Not required, but preferably use C# language

Actual testing:

  • I tried to evaluate #2 but there is no VS project sample with all modules working together (which seems a little bit complex to assemble).
  • I currently evaluate #6 which seems to work fine (I corrected a minor bug). It seems to fits most points but #3. But it seems to be the closest to my needs yet. It also uses Roslyn which appears to me a positive aspect because it is the Microsoft compiler which should always be up to date.

I'm still waiting to see any feedback from anybody with either other better solutions or any advise to help me take a better decision.


Solution

  • After some thought, trials and errors. My needs become clearer and my understanding of to current state about Roslyn development was also better.

    I realized that Oleg Shilo (Author of CS-Script) was right about the fact that Roslyn is not ready (2014-10-21) to help me for intellisense. But I think it should happen relatively soon. I think it should worth the wait. But it can compile and run code into the same running app I would like to run tested in.

    Although any other approach could have probably work better right now. I think that a solution like RoslynPad would be closer to the ideal solution for my needs. Most other proposed solution where nice for general scripting but not as good as RoslynPad for inside app own scripting... at least according to my opinion.

    I then fixed some little issues in RoslynPad and hook it to the newest AvalonEdit which also fixes some other issues with auto-completion (but still with few bugs).

    I now get needs filled up as this:

    • #1 Partial (ready for full when Roslyn will supported and documented it)
    • #2 Full
    • #3 No (ready for full when Roslyn will supported and documented it)
    • #4 Full
    • #5 Full

    Thanks a lots to all people giving me ideas, links and very nice advise.