I have to develop an application that can execute some functions from a user created text files.
I searched and found some threads :
Execute code lines from a text file in C#
How to compile a C# file with Roslyn programmatically?
But I did not find what I was looking for ...
I don't want to execute input string codes as external or separated name spaces ...
what I'm looking for is executing some part of main codes from a string value
Example :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace ConsoleApp1
{
public partial class Window : MainWindow
{
string internal_message = "Hello World!"; /// a value set in main code
public UserControl1()
{
InitializeComponent();
}
//////////////////////////////////// I want this part be executed from a string [
void Saysomething()
{
MessageBox.Show(internal_message); /// get internal message from main values
}
//////////////////////////////////// ]
private void Button_Click(object sender, RoutedEventArgs e)
{
Saysomething(); //// run function executed from text data
}
}
}
My functions are complex and I need a general solution in 3ds max maxscript there's a function we call "Execute"
it takes string and execute it as dynamic code in same code and namespace :
myvalue = "val = 30";
execute(myvalue);
print val;
/// result
30
I need the same in c# And please do not use roslyn as much as possible.