示例#1
0
        private void SetUserCreatedObjs(object[] objs)
        {
            treeView.Nodes[0].Nodes.Clear();
            foreach (object obj in objs)
            {
                treeView.Nodes[0].Nodes.Add(new TreeNode(obj.GetType().Name));
                foreach (PropertyInfo f in obj.GetType().GetProperties())
                {
                    InfoCRUD I = new InfoCRUD {
                        type = f.PropertyType
                    };
                    I.Value = f.GetValue(obj);
                    object[] attrs = f.GetCustomAttributes(typeof(NormalNameAttribute), false);
                    I.Name  = attrs.Length > 0 ? ((NormalNameAttribute)attrs[0]).Name : f.Name;
                    I.Name += ": ";
                    treeView.Nodes[0].LastNode.Nodes.Add(new TreeNode(I.Name + I.Value.ToString()));
                    treeView.Nodes[0].LastNode.LastNode.Tag = I;
                }
                InfoCRUD i = new InfoCRUD {
                    type = obj.GetType()
                };
                treeView.Nodes[0].LastNode.Tag = i;
            }

            treeView.Nodes[0].ExpandAll();
        }
示例#2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            treeView.Nodes[0].Nodes.Add(new TreeNode(comboBox.Text));
            foreach (PropertyInfo f in ((Type)comboBox.SelectedItem).GetProperties())
            {
                InfoCRUD I = new InfoCRUD {
                    type = f.PropertyType
                };

                object[] attrs = f.GetCustomAttributes(typeof(NormalNameAttribute), false);
                I.Name  = attrs.Length > 0 ? ((NormalNameAttribute)attrs[0]).Name : f.Name;
                I.Name += ": ";

                if (I.Name == "Id: ")
                {
                    I.Value = Guid.NewGuid();
                    treeView.Nodes[0].LastNode.Nodes.Add(new TreeNode(I.Name + I.Value.ToString()));
                }
                else
                {
                    treeView.Nodes[0].LastNode.Nodes.Add(new TreeNode(I.Name));
                    I.Value = f.PropertyType == typeof(string) ? "" : Activator.CreateInstance(f.PropertyType);
                }
                treeView.Nodes[0].LastNode.LastNode.Tag = I;
            }
            InfoCRUD i = new InfoCRUD {
                type = (Type)comboBox.SelectedItem
            };

            treeView.Nodes[0].LastNode.Tag = i;

            treeView.Nodes[0].ExpandAll();
            if (comboBoxValue.Enabled == true)
            {
                comboBoxValue_Fill();
            }
        }