Пример #1
0
        public Frame()
        {
            InitializeComponent();
            this.DoubleBuffered = true;

            Type typeSkillFrameAction = typeof(SkillFrameAction);

            foreach (var s in typeSkillFrameAction.GetEnumNames())
            {
                System.Reflection.FieldInfo fi = typeSkillFrameAction.GetField(s);
                EditorNameAttribute         menuNameAttribute = XPropDescriptor.GetCustomAttribute <EditorNameAttribute>(fi);
                List <string> menuItems = new List <string>();
                if (menuNameAttribute == null)
                {
                    menuItems.Add("通用");
                    menuItems.Add(s);
                }
                else
                {
                    menuItems.AddRange(menuNameAttribute.EditorName.Split('/'));
                    menuItems.Add(s);
                }
                AddMenu(menuItems);
            }
            contextMenuStrip1.ItemClicked += contextMenuStrip1_OnItemClicked;
        }
Пример #2
0
        public PropertyDescriptorCollection GetProperties(System.Attribute[] attributes)
        {
            object child = _obj;

            FieldInfo[] fi_list           = child.GetType().GetFields();
            List <PropertyDescriptor> pds = new List <PropertyDescriptor>();

            for (int i = 0; i < fi_list.Length; i++)
            {
                Type            type = fi_list[i].FieldType;
                object          v    = fi_list[i].GetValue(child);
                XPropDescriptor xp   = new XPropDescriptor(child, fi_list[i], attributes);
                pds.Add(xp);
            }
            return(new PropertyDescriptorCollection(pds.ToArray()));
        }
Пример #3
0
        List <PropertyDescriptor> GetChildProperties1(object child, System.Attribute[] attributes)
        {
            if (child.GetType().IsArray)
            {
                List <PropertyDescriptor> pds = new List <PropertyDescriptor>();
                Array array = (Array)child;
                for (int i = 0; i < array.Length; i++)
                {
                    XArrayDescriptor xp = new XArrayDescriptor(array, i, child.GetType().GetElementType(), attributes);
                    pds.Add(xp);
                }

                return(pds);
            }
            else
            {
                FieldInfo[] fi_list           = child.GetType().GetFields();
                List <PropertyDescriptor> pds = new List <PropertyDescriptor>();
                for (int i = 0; i < fi_list.Length; i++)
                {
                    Type   type = fi_list[i].FieldType;
                    object v    = fi_list[i].GetValue(child);
                    if (type.IsPrimitive || type == typeof(string) || type.IsEnum)  //基本类型
                    {
                        XPropDescriptor xp = new XPropDescriptor(child, fi_list[i], attributes);
                        pds.Add(xp);
                    }
                    else if ((type.IsValueType || type.IsClass))   //结构体
                    {
                        //if (v == null)
                        //{
                        //    v = Activator.CreateInstance(type);
                        //    fi_list[i].SetValue(child, v);
                        //}
                        XPropDescriptor xp = new XPropDescriptor(child, fi_list[i], attributes);
                        pds.Add(xp);
                    }
                }
                return(pds);
            }
        }