예제 #1
0
        internal void Setup(String invokeActionName,
                            String invokeActionName2,
                            EventHandler invokeDelegate,
                            EventHandler invokeDelegate2,
                            TreeNode node,
                            Object obj,
                            MemberInfo memberInfo,
                            ParameterInfo[] parameters)
        {
            // We are already all set
            if (_node == node)
            {
                return;
            }

            Clear();
            _node = node;

            // Add the parameters of the method or property indexers
            if (parameters != null)
            {
                for (int i = 0; i < parameters.Length; i++)
                {
                    ParameterInfo param          = parameters[i];
                    Object        propIndexValue = null;

                    // See if the current object value of the node is
                    // set to something, and if so, put the index
                    // value in the index parameter
                    if (memberInfo is PropertyInfo)
                    {
                        ObjectTypeTreeNode otNode = (ObjectTypeTreeNode)node;
                        if (otNode.CurrentPropIndexValues != null)
                        {
                            propIndexValue = otNode.CurrentPropIndexValues[i];
                        }
                    }

                    ParamControlInfo pci = AddParam(propIndexValue, param.ParameterType, param.Name, param, !FIELD_PROP_VALUE);

                    if (memberInfo is PropertyInfo)
                    {
                        pci._propertyIndexer = true;
                    }
                }
            }

            // String class is a special case for a type node;
            if (node is TypeTreeNode)
            {
                Type type = ((TypeTreeNode)node).Type;
                if (type.Equals(typeof(String)))
                {
                    AddParam(null, typeof(String), "value", null, FIELD_PROP_VALUE);
                }
            }

            // Handle the field/property value "parameters"
            if (memberInfo != null)
            {
                if (!SetupFieldPropValues(node, obj, memberInfo, parameters))
                {
                    return;
                }
            }

            ArrayList paramList = new ArrayList();

            foreach (ParamControlInfo param in _paramInfos)
            {
                paramList.Add(param);
            }

            // Supress set button on indexed properties, which
            // is always the 2nd button
            if (memberInfo is PropertyInfo)
            {
                PropertyInfo propInfo = (PropertyInfo)memberInfo;
                if (ParamControlInfo.IsUnhandledStruct(propInfo.PropertyType))
                {
                    invokeActionName2 = null;
                }
            }

            // Calc tab offset to make up for the buttons below
            int tabOffset = 0;

            if (invokeActionName != null)
            {
                tabOffset++;
            }
            if (invokeActionName2 != null)
            {
                tabOffset++;
            }

            Utils.AddHasControls(this, paramList, tabOffset);

            if (invokeActionName != null || invokeActionName2 != null)
            {
                Panel bp = new Panel();
                bp.Dock   = DockStyle.Top;
                bp.Height = Utils.BUTTON_HEIGHT;
                bp.Width  = Width;

                Button b;
                if (invokeActionName != null)
                {
                    b        = Utils.MakeButton(invokeActionName);
                    b.Dock   = DockStyle.Right;
                    b.Click += invokeDelegate;
                    bp.Controls.Add(b);
                    bp.TabIndex = --tabOffset;
                }

                if (invokeActionName2 != null)
                {
                    b        = Utils.MakeButton(invokeActionName2);
                    b.Dock   = DockStyle.Right;
                    b.Click += invokeDelegate2;
                    bp.Controls.Add(b);
                    bp.TabIndex = --tabOffset;
                }

                Controls.Add(bp);
            }
        }
예제 #2
0
        // Returns true if processing should continue, false otherwise
        internal bool SetupFieldPropValues(TreeNode node,
                                           Object obj,
                                           MemberInfo memberInfo,
                                           ParameterInfo[] parameters)
        {
            if (memberInfo is PropertyInfo)
            {
                if (((PropertyInfo)memberInfo).CanWrite)
                {
                    PropertyInfo pi = (PropertyInfo)memberInfo;

                    // If not indexed, a struct property is treated like
                    // a struct field; nothing is done in the param panel.
                    // If indexed, we need to show the index
                    if (ParamControlInfo.IsUnhandledStruct(pi.PropertyType))
                    {
                        if (parameters.Length > 0)
                        {
                            return(true);
                        }
                        return(false);
                    }

                    if (obj == null)
                    {
                        AddParam(null, pi.PropertyType, "value", null, FIELD_PROP_VALUE);
                    }
                    else
                    {
                        ObjectTypeTreeNode otNode = (ObjectTypeTreeNode)node;
                        Object             value  = null;
                        try {
                            value = pi.GetValue(obj, otNode.CurrentPropIndexValues);
                        } catch (Exception ex) {
                            TraceUtil.WriteLineInfo
                                (this,
                                "Exception in getting property "
                                + "value for " + pi + ": " + ex);

                            // Use the value from ObjectInfo, this is
                            // necessary for the property that can only
                            // be set, we want to show the last value we
                            // set it to, if possible
                            value = otNode.ObjectInfo.Obj;
                        }
                        AddParam(value, pi.PropertyType, "value", null, FIELD_PROP_VALUE);
                    }
                }
                else
                {
                    // Not indexed, nothing to invoke, if index,
                    if (parameters == null || parameters.Length == 0)
                    {
                        AddMessage("Property is read only");
                        return(false);
                    }
                }
            }
            else if (memberInfo is FieldInfo)
            {
                if (!((FieldInfo)memberInfo).IsLiteral)
                {
                    FieldInfo fi = (FieldInfo)memberInfo;

                    // Structs are handled by expanding their members
                    if (ParamControlInfo.IsUnhandledStruct(fi.FieldType))
                    {
                        return(false);
                    }

                    if (obj == null)
                    {
                        AddParam(null, fi.FieldType, "value", null, FIELD_PROP_VALUE);
                    }
                    else
                    {
                        Object value = null;
                        try {
                            value = fi.GetValue(obj);
                        } catch (Exception ex) {
                            TraceUtil.WriteLineInfo
                                (this,
                                "Exception in getting field "
                                + "value for " + fi + ": " + ex);

                            // Just ignore it
                        }
                        AddParam(value, fi.FieldType, "value", null, FIELD_PROP_VALUE);
                    }
                }
                else
                {
                    AddMessage("Constant; cannot be changed");
                    return(false);
                }
            }
            else if (memberInfo is EventInfo)
            {
                return(false);
            }
            return(true);
        }