/// <summary>
        /// Deserializes an expression of the form:
        ///
        /// System.Drawing.Color.FromArgb(0, 192, 0)
        /// </summary>
        object DeserializeMethodCallExpression(CallExpression callExpression, MemberExpression memberExpression)
        {
            PythonControlFieldExpression field = PythonControlFieldExpression.Create(memberExpression);
            Type type = GetType(field);

            if (type != null)
            {
                foreach (MethodInfo method in type.GetMethods(BindingFlags.Public | BindingFlags.Static))
                {
                    if (method.Name == field.MemberName)
                    {
                        if (method.GetParameters().Length == callExpression.Args.Count)
                        {
                            return(method.Invoke(null, GetArguments(callExpression).ToArray()));
                        }
                    }
                }
            }
            else
            {
                // Maybe it is a call to a constructor?
                type = componentCreator.GetType(field.FullMemberName);
                if (type != null)
                {
                    return(componentCreator.CreateInstance(type, GetArguments(callExpression), null, false));
                }
            }
            return(null);
        }
        public override bool Walk(AssignmentStatement node)
        {
            if (!walkingInitializeComponentMethod)
            {
                return(false);
            }

            if (node.Left.Count > 0)
            {
                MemberExpression lhsMemberExpression = node.Left[0] as MemberExpression;
                NameExpression   lhsNameExpression   = node.Left[0] as NameExpression;
                if (lhsMemberExpression != null)
                {
                    fieldExpression = PythonControlFieldExpression.Create(lhsMemberExpression);
                    WalkMemberExpressionAssignmentRhs(node.Right);
                }
                else if (lhsNameExpression != null)
                {
                    CallExpression callExpression = node.Right as CallExpression;
                    if (callExpression != null)
                    {
                        object instance = CreateInstance(lhsNameExpression.Name.ToString(), callExpression);
                        if (instance == null)
                        {
                            ThrowCouldNotFindTypeException(callExpression.Target as MemberExpression);
                        }
                    }
                }
            }
            return(false);
        }
        /// <summary>
        /// Walks a method call. Typical method calls are:
        ///
        /// self._menuItem1.Items.AddRange(...)
        ///
        /// This method will execute the method call.
        /// </summary>
        void WalkMethodCall(CallExpression node)
        {
            // Try to get the object being called. Try the form first then
            // look for other controls.
            object member = PythonControlFieldExpression.GetMember(component, node);
            PythonControlFieldExpression field = PythonControlFieldExpression.Create(node);

            if (member == null)
            {
                member = field.GetMember(componentCreator);
            }

            // Execute the method on the object.
            if (member != null)
            {
                object[] args = deserializer.GetArguments(node).ToArray();
                InvokeMethod(member, field.MethodName, args);
            }
        }
        /// <summary>
        /// Walks a statement of the form:
        ///
        /// self.a += self.b
        /// </summary>
        public override bool Walk(AugmentedAssignStatement node)
        {
            if (!FoundInitializeComponentMethod)
            {
                return(false);
            }

            MemberExpression             eventExpression = node.Left as MemberExpression;
            string                       eventName       = eventExpression.Name.ToString();
            PythonControlFieldExpression field           = PythonControlFieldExpression.Create(eventExpression);

            MemberExpression eventHandlerExpression = node.Right as MemberExpression;
            string           eventHandlerName       = eventHandlerExpression.Name.ToString();

            IComponent currentComponent = fieldExpression.GetObject(componentCreator) as IComponent;

            EventDescriptor    eventDescriptor    = TypeDescriptor.GetEvents(currentComponent).Find(eventName, false);
            PropertyDescriptor propertyDescriptor = componentCreator.GetEventProperty(eventDescriptor);

            propertyDescriptor.SetValue(currentComponent, eventHandlerName);
            return(false);
        }
        /// <summary>
        /// Deserializes expressions of the form:
        ///
        /// 1) System.Windows.Forms.Cursors.AppStarting
        /// </summary>
        object Deserialize(MemberExpression memberExpression)
        {
            PythonControlFieldExpression field = PythonControlFieldExpression.Create(memberExpression);
            Type type = GetType(field);

            if (type != null)
            {
                if (type.IsEnum)
                {
                    return(Enum.Parse(type, field.MemberName));
                }
                else
                {
                    BindingFlags propertyBindingFlags = BindingFlags.Public | BindingFlags.GetField | BindingFlags.Static | BindingFlags.Instance;
                    PropertyInfo propertyInfo         = type.GetProperty(field.MemberName, propertyBindingFlags);
                    if (propertyInfo != null)
                    {
                        return(propertyInfo.GetValue(type, null));
                    }
                }
            }
            return(componentCreator.GetInstance(PythonControlFieldExpression.GetVariableName(field.MemberName)));
        }