Inheritance: IAssignableReference
Example #1
0
        private static void GetObjectFromContainerAndNameReference(object container, string memberName, CodeContext codeContext, 
            ref object foundValue, ref bool wasFound)
        {
            object originalContainer = container;

            if (container == null)
            {
                int stackDepth = -1;
                codeContext.GetVariableInformation(memberName, out stackDepth);

                if (stackDepth != -1)
                {
                    StackVariableReference reference = new StackVariableReference();
                    reference.StackIndex = stackDepth;
                    reference.VariableName = memberName;
                    reference.CodeContext = codeContext;

                    foundValue = reference;
                    wasFound = foundValue != null;
                }
            }
            else
            {
                
                Type typeToGetFrom = null;

                if (container is IAssignableReference)
                {
                    container = ((IAssignableReference)container).CurrentValue;
                }

                if (container is Type)
                {
                    typeToGetFrom = container as Type;
                }
                else if (container != null)
                {
                    typeToGetFrom = container.GetType();
                }

                AssignableReference assignableReference = null;

                var fieldInfo = typeToGetFrom.GetField(memberName);
                if (fieldInfo != null)
                {
                    assignableReference = new AssignableReference();
                    assignableReference.FieldInfo = fieldInfo;
                    assignableReference.Owner = container;

                    if (originalContainer is IAssignableReference)
                    {
                        assignableReference.Parent = originalContainer as IAssignableReference;
                    }
                }
                else
                {
                    var propertyInfo = typeToGetFrom.GetProperty(memberName);
                    if (propertyInfo != null)
                    {
                        assignableReference = new AssignableReference();
                        assignableReference.PropertyInfo = propertyInfo;
                        assignableReference.Owner = container;

                        if (originalContainer is IAssignableReference)
                        {
                            assignableReference.Parent = originalContainer as IAssignableReference;
                        }
                    }
                }

                foundValue = assignableReference;
                wasFound = foundValue != null;
            }
        }
Example #2
0
        internal object EvaluateStatement(Statement statement, CodeContext codeContext, ExpressionParseType parseType)
        {
            if (statement is VariableDeclarationStatement)
            {
                VariableDeclarationStatement vds = statement as VariableDeclarationStatement;

                var astType = vds.Type;

                Type type = TypeManager.GetTypeFromString(astType.GetText());

                var variables = vds.Variables;

                string addedVariable = null;

                foreach (var variable in variables)
                {
                    // right now we only support one declaration per line, will need to
                    // expand this later
                    addedVariable = variable.Name;
                    codeContext.VariableStack.Last().Add(addedVariable, null);
                    break;
                }

                if (parseType == ExpressionParseType.Evaluate)
                {
                    return null; // hasn't been assigned yet
                }
                else
                {
                    StackVariableReference svr = new StackVariableReference();
                    int index;
                    codeContext.GetVariableInformation(addedVariable, out index);
                    svr.StackIndex = index;
                    svr.VariableName = addedVariable;
                    svr.TypeOfReference = type;
                    return svr;
                }
            }
            else
            {
                return null;
            }
        }