private void AssignValue(string newVariableDeclarationType, string leftOfEquals, string rightOfEquals, CodeContext codeContext,
AssignmentOperatorType assignOperator)
{
ElementRuntime elementRuntime = codeContext.ContainerInstance as ElementRuntime;
IElement element = null;
if (elementRuntime != null)
{
element = elementRuntime.AssociatedIElement;
}
CustomVariable customVariable = CreateCustomVariableFor(newVariableDeclarationType, leftOfEquals, rightOfEquals, elementRuntime, codeContext);
if (customVariable.Name.CountOf('.') > 1)
{
throw new Exception("Script parsing doesn't support setting properties/fields on properties/fields. In other words, assigning something.X is okay, but not something.Position.x");
}
mParserLog.AppendLine("Left side: " + leftOfEquals + " RightSide: " + rightOfEquals + " Resulting variable: " + customVariable);
if (newVariableDeclarationType != null)
{
TopOfVariableStack[leftOfEquals] = customVariable.DefaultValue;
codeContext.VariableStack.Last().Add(leftOfEquals, customVariable.DefaultValue);
}
else if (customVariable != null)
{
if (codeContext.ContainerInstance != null)
{
ElementRuntime runtime = codeContext.ContainerInstance as ElementRuntime;
runtime.SetCustomVariable(customVariable, runtime.AssociatedIElement, customVariable.DefaultValue, true, VariableSettingOptions.LiteralSet );
}
else
{
var reference = mExpressionParser.EvaluateExpression(leftOfEquals, codeContext, ExpressionParseType.GetReference);
bool wasAssigned = false;
wasAssigned = TryAssignIAssignableReference(assignOperator, customVariable, reference);
if (!wasAssigned)
{
throw new Exception("Could not assign the value");
}
}
}
}