0

I want the user to create a variable of type float and the variable's value will be reassessed multiple times based on a text function the user supplies. A simple example would be: Val1 = Val1 * UserVariables.Count + 5. Each time the variable named Val1 is assessed in the program (outside the user's control) it will reset its value. Some detail on the user variable below.

public class UserVariable()
{
    public string Name; // Say Val1
    public Type Type; // Say float
    public dynamic Value; // would be determined by Type
    public string Input; // the user's function

    public void EvalutateValue()
    {
        // Value = [Run something like Visual Studio Interactive Window line command]
    }
}

Thanks in advance for any suggestions

Minho17
  • 44
  • 6
  • I don't really understand what you're asking for. How to update a value whenever the user does something? Or evaluating a user-input string like a command? – lucidbrot Feb 04 '21 at 08:56
  • It sounds like you want to run some code from a string... It is generally risky idea unless users are absolutely trusted, but [duplicate](https://stackoverflow.com/questions/4629/how-can-i-evaluate-c-sharp-code-dynamically) shows you how to do that if you assessed the risks. If that is not what you are asking - [edit] the question to clarify. – Alexei Levenkov Feb 04 '21 at 09:04
  • @lucidbrot I am building a discrete event simulation. using a particular process flow chart block, the user will have the flexibility of adding their own variable to track statistics. In this block they will create a variable by typing in the name and value (likely a function). To avoid creating a detailed string parser to sort out all possible math combinations I want to store the compiled equation's result directly into the variable. UserVariable = CompiledResultOf(TextEquation). – Minho17 Feb 04 '21 at 15:30
  • @AlexeiLevenkov thanks for sharing that! Yes, I have been reading into compiling; but I getting back to square one - considering that compiledResults are in string format. I am curious, as a vivid VS user, is it that functions replicating Interactive window and watches cannot be directly implemented into our application? Value = InterActiveWindow.GetResultOf("Value * 3") such that Value now equals Value * 3? – Minho17 Feb 04 '21 at 15:34

0 Answers0