.NET Question - Running code post release

bchip

Expert Member
Joined
Mar 12, 2013
Messages
1,324
Reaction score
418
Hi everyone

Just need a pointer in the right direction as Im not coming right with Google.
I'm messing around with an app. In the app you write code that does XYZ - Its a script.
The app compiles and everyone is happy.
I dont want all the scripts to be compiled in the final solution, I want to save the scripts in separate files
and then as I run the program I "open file" script and run.

How would one do this?
Let me know if the question is unclear.

Thanks
 
Do you want to run c# code but via a desktop app? What is the difference between that and say letting the user run it in Visual Studio or in their browser at https://dotnetfiddle.net/ ?

That should give enough details for someone to answer.
 
To answer some of the questions / help with clearer understanding
Its a desktop app.
Currently I have the app that does calcs for me using my objects.
I compile everything and I can reference those calcs.

Trying to do this conceptually but the not sure if I'm making it worse
with this bad example:

desktop app [Main]
public void main()
{
int SquareSize = 10;
Square emp = new Square();
double d = emp.getSize(10);
}

seperate class file:
class Square {
int width = 10;
int height = 10;

public double getSize(int dim)
{
return width*height*dim;
}

}

Because Ive got values in the main desktop app that I need to send through
I also dont want to precode every (in this case) Square, I want the user to be able
to add Rectangles, Circles, etc later on

So eventually I want to have some kind of GetCodeFromFile function
run that code with the standard getSize method, with inputs of 10.
 
Last edited:
in what language do you foresee your client define the other objects / operations?
 
I my software where I need extensibility, I do the following:
- Firstly I create an interface to which the module needs to conform. The application itself only references the interface
- Then I create separate assemblies for the different implementations. Usually one assembly per implementation, but you can combine
- Then I have the concept of a Manifest that is simply an XML file that defines the interface type and then all the possible implementations that need to be/may be loaded for the interface. The manifest file defines the interface, the implementing assembly, optionally the implementation type, and also the ctor parameters if required.
The above works when your client will use VS and code in C#.

The alternate is to load the C# code of the implementing class and compile using Roslyn (C# compiler assemblies).

Or you can, in the app or the files, purely define the 'rules' and then use Reflection.Emit to generate IL code and then compile.

It all depends on what level of control you want your client to have as well as how far they may stray from a 'template' and if the interface/behavioural contract will change
 
Did I read this right?

He wants dynamic hard coding of values because he us too lazy to pass it in as a parameter?
 
Most people typically embed an interpreter to run code on the fly. LUA and Python are commonly embedded. I’ve done this before, embedding them into C++.
 
Thanks for all the feedback!
Will be going through each avenue then...lots of new concepts here :)
 
All this feedback and only 1 mention of Reflection?
 
Nope that'll be 2 if you consider; Expression is similar to Delegate.CreateDelegate or Reflection.Emit

They don't pay me to count... :P

Wondering if I should dust off my little plugin manager I wrote a few years back. The only thing I couldn't figure out was not to lock the file (so you can update it without stopping current execution), shadow copy didn't work either (or at least I didn't try that hard)
 
Top
Sign up to the MyBroadband newsletter
X