Skip to content

Instantly share code, notes, and snippets.

@davidneumann
Last active August 3, 2020 20:54
Show Gist options
  • Save davidneumann/4633442e274e1463ba987833ded18e36 to your computer and use it in GitHub Desktop.
Save davidneumann/4633442e274e1463ba987833ded18e36 to your computer and use it in GitHub Desktop.
public class SomeHelperClass {
void checkForVariables(string lineToCheck)
{
lineToCheck = lineToCheck.Replace(" ", "");
string variableName = "";
string value = "";
var groups = lineToCheck.Split("=");
//If there are no = signs then the length will be 0. If there is more than 1 then the length will be above 2.
if(groups.Length != 2)
{
return;
}
variableName = groups[0];
value = groups[1];
// check if it's a string
bool isString = value[0] == '\"' && value[value.length-1] == '\"';
double number;
if (!isString)
{
if (double.TryParse(value, out number))
ConsoleVariables.variables[variableName] = new DoubleValue(number);
else
{
if(ConsoleVariables.variables.ContainsKey(value))
{
if(ConsoleVariables.variables[value] is DoubleValue)
ConsoleVariables.variables[variableName] = new DoubleValue(((DoubleValue)ConsoleVariables.variables[value]).Value);
else if(ConsoleVariables.variables[value] is StringValue)
ConsoleVariables.variables[variableName] = new StringValue(((StringValue)ConsoleVariables.variables[value]).Value);
}
}
}
else
{
ConsoleVariables.variables[variableName] = new StringValue(value);
}
}
}
public class BaseValue
{
}
public class DoubleValue : BaseValue
{
public double Value { get; set; }
public DoubleValue(double value)
{
Value = value;
}
}
public class StringValue : BaseValue
{
public string Value { get; set; }
public StringValue(string value)
{
Value = value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment