public string GetTypeStringForValue(string leftOfEquals, ElementRuntime elementRuntime, CodeContext codeContext, out Type runtimeType)
{
// try using the new method:
var leftReference = mExpressionParser.EvaluateExpression(leftOfEquals, codeContext, ExpressionParseType.GetReference);
if (leftReference != null)
{
if (leftReference is IAssignableReference)
{
Type type = ((IAssignableReference)leftReference).TypeOfReference;
runtimeType = type;
string toReturn = null;
if (runtimeType != null)
{
toReturn = runtimeType.FullName;
}
return toReturn;
}
else
{
runtimeType = null;
return null;
}
}
else
{
string leftSideRaw = leftOfEquals;
string leftSideContainer = null;
if (leftOfEquals.Contains('.'))
{
// That means the user is setting a value on a contained object, so let's see what the raw variable is
int lastDot = leftOfEquals.LastIndexOf('.');
leftSideRaw = leftOfEquals.Substring(lastDot + 1, leftSideRaw.Length - (lastDot + 1));
leftSideContainer = leftOfEquals.Substring(0, lastDot);
}
if (leftSideContainer == null)
{
if (elementRuntime != null)
{
if (IsStateVariable(leftSideRaw, elementRuntime))
{
runtimeType = typeof(string);
return "String";
}
}
FieldInfo fieldInfo = mAllFields.GetFieldByName(leftSideRaw);
if (fieldInfo != null)
{
runtimeType = fieldInfo.FieldType;
return fieldInfo.FieldType.ToString();
}
PropertyInfo propertyInfo = mAllProperties.GetPropertyByName(leftSideRaw);
if (propertyInfo != null)
{
runtimeType = propertyInfo.PropertyType;
return propertyInfo.PropertyType.ToString();
}
}
// reverse loop so we get the inner-most variables first
for (int i = mCallStackVariables.Count - 1; i > -1; i--)
{
Dictionary<string, object> variableDictionary = mCallStackVariables[i];
if (variableDictionary.ContainsKey(leftSideRaw))
{
runtimeType = variableDictionary[leftSideRaw].GetType();
return runtimeType.ToString();
}
}
if (leftSideContainer != null)
{
ElementRuntime containerElementRuntime = elementRuntime.GetContainedElementRuntime(leftSideContainer);
if (containerElementRuntime != null)
{
return GetTypeStringForValue(leftSideRaw, containerElementRuntime, codeContext, out runtimeType);
}
}
// If we got this far we should try to get the type through reflection
GetTypeFromReflection(leftOfEquals, out runtimeType, null);
if (runtimeType != null)
{
return runtimeType.ToString();
}
else
{
return null;
}
}
}