// override object.Equals public override bool Equals(object obj) { if (obj == null || GetType() != obj.GetType()) { return(false); } TypeAndInterfaceArr targetObj = (TypeAndInterfaceArr)obj; if (this.ClassType != targetObj.ClassType) { return(false); } if (!Utility.IsAllEquals <Type>(this.Interfaces, targetObj.Interfaces)) { return(false); } if (this.Panel != targetObj.Panel) { return(false); } return(true); }
/// <summary> /// 工厂模式创建控件:针对 [静态类] 的属性中是否设定定制特性创建 /// </summary> static public AutoLayoutPanel CreatePanel(Type attributeType, Type staticClassType, bool needCache, bool singleObject) { TypeAndInterfaceArr typeAndInterface = new TypeAndInterfaceArr(staticClassType, attributeType.FullName); AutoLayoutPanel tempPanel = CreatePanelCore(attributeType, typeAndInterface, true, needCache, singleObject); return(tempPanel); }
/// <summary> /// 初始化控件 /// </summary> private void CreateControlForPanel(TypeAndInterfaceArr typeAndInterface) { #region 取得一个名字赋给This StringBuilder nameSb; { nameSb = new StringBuilder(); nameSb.Append("Control_").Append(typeAndInterface.ClassType).Append("_"); if (typeAndInterface.Interfaces != null) { foreach (Type ty in typeAndInterface.Interfaces) { nameSb.Append(ty.Name).Append("_"); } } } this.Name = nameSb.ToString(); #endregion //根据Type来生成控件 this.BuildControlForType(typeAndInterface); #region 根据接口来生成控件//todo:未做 Type[] listInterface = typeAndInterface.Interfaces; #endregion this.AutoScroll = true; this.Dock = DockStyle.Fill; }
/// <summary> /// 工厂模式创建控件:针对 [对象] 的属性中是否设定定制特性创建 /// </summary> static public AutoLayoutPanel CreatePanel(Type attributeType, object[] objs, bool needCache, bool singleObject) { Type[] listInterface; Type objsType = Utility.Type.GetCommonTypeService(objs, out listInterface); TypeAndInterfaceArr typeAndInterface = new TypeAndInterfaceArr(objsType, listInterface, attributeType.FullName); AutoLayoutPanel tempPanel = CreatePanelCore(attributeType, typeAndInterface, false, needCache, singleObject); return(tempPanel); }
/// <summary> /// 构造函数: /// 根据Type构建控件本身及子控件 /// </summary> protected AutoLayoutPanel(Type attributeType, TypeAndInterfaceArr typeAndInterface, bool isStatic, bool singleObject) { this.IsNewOpenForAddEvent = true; OwnTypeAndInterfaceArr = typeAndInterface; IsStatic = isStatic; this._autoAttributeType = attributeType; this.SingleObject = singleObject; //this.Padding = new Padding(10);//可进行设置FlowLayoutPanel的边距来改变所有控件的起始位置的不同,以消除控件太靠近边缘的美观 CreateControlForPanel(OwnTypeAndInterfaceArr); }
/// <summary> /// 上两个重载方法的内部子方法:创建Panel /// </summary> static private AutoLayoutPanelEx CreatePanelCore(Type attributeType, TypeAndInterfaceArr typeAndInterface, bool isStatic, bool needCache, bool singleObject) { ///不需要缓存,直接chuanjiang创建 if (!needCache) { return(new AutoLayoutPanelEx(attributeType, typeAndInterface, isStatic, singleObject)); } AutoLayoutPanelEx tempPanel = null; ///单建模式AutoLayoutPanel, if (!autoPanelDictionary.TryGetValue(typeAndInterface, out tempPanel) || tempPanel.IsDisposed) { tempPanel = new AutoLayoutPanelEx(attributeType, typeAndInterface, isStatic, singleObject); autoPanelDictionary[typeAndInterface] = tempPanel; } return(tempPanel); }
/// <summary> /// 构造函数 /// </summary> protected AutoLayoutPanelEx(Type attributeType, TypeAndInterfaceArr typeAndInterface, bool isStatic, bool singleObject) : base(attributeType, typeAndInterface, isStatic, singleObject) { }
/// <summary> /// 根据Type来生成控件 /// </summary> private void BuildControlForType(TypeAndInterfaceArr typeAndInterface) { Type type = typeAndInterface.ClassType; //PropertyInfo[] properties = null; MemberInfo[] memberInfos = null; #region GetProperties if (IsStatic) { memberInfos = type.GetMembers( BindingFlags.Static | BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.SetProperty | BindingFlags.InvokeMethod); //properties = type.GetProperties( // BindingFlags.Static | // BindingFlags.Public | // BindingFlags.GetProperty | // BindingFlags.SetProperty); } else { memberInfos = type.GetMembers( BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.SetProperty | BindingFlags.InvokeMethod); /////取当前类的属性 //properties = type.GetProperties( // BindingFlags.Instance | // BindingFlags.Public | // BindingFlags.GetProperty | // BindingFlags.SetProperty); /////取当前类的属性 //properties = type.GetProperties( // BindingFlags.Instance | // BindingFlags.Public | // BindingFlags.GetProperty | // BindingFlags.SetProperty | // BindingFlags.DeclaredOnly); /////取派生类的属性 //PropertyInfo[] baseProperties = type.BaseType.GetProperties( // BindingFlags.Instance | // BindingFlags.Public | // BindingFlags.GetProperty | // BindingFlags.SetProperty | // BindingFlags.DeclaredOnly); /////将dedaoshu得到的属性合成一个数组 //PropertyInfo[] tempNew = new PropertyInfo[properties.Length + baseProperties.Length]; //Array.Copy(properties, tempNew, properties.Length); //Array.Copy(baseProperties, 0, tempNew, properties.Length, baseProperties.Length); //properties = tempNew; } #endregion List <AutoAttributeData> attList = new List <AutoAttributeData>(); //利用反射得到属性中的定制特性 by lisuye on 2008年5月29日 //foreach类型里的所有属性是否有定制特性 foreach (MemberInfo info in memberInfos) { object[] propertyPadValues = info.GetCustomAttributes(_autoAttributeType, true); if (propertyPadValues.Length <= 0) { continue;//无定制特性 } //foreach单个属性里的定制特性,Add到attList中 foreach (AutoLayoutPanelAttribute att in propertyPadValues) { attList.Add(new AutoAttributeData(info, att)); } } //根据定制特性绘制groupbox控件 by lisuye on 2008年5月29日 //如果attList.Count小于或等于0的话证明该类型没有定制特性 if (attList.Count > 0) { ///根据AutoAttributeData集合获得GroupAttsData集合 SortedDictionary <int, GroupAttsData> groupBoxList = ToGroupDatas(attList); if (groupBoxList != null) { foreach (var pair in groupBoxList) { //设置GroupBox的时候,则需要将groupBox的相关属性放在第个组的第一项(规定) AutoAttributeData lastAutoAtt = pair.Value.AutoAttributeDatas[0]; bool isGroupDockTop = lastAutoAtt.Attribute.GroupBoxDockTop; //当前的组合框是否要置顶 string groupText = lastAutoAtt.Attribute.GroupBoxUseWinStyleText; //当前的组合框的显示文本 bool useGroup = lastAutoAtt.Attribute.GroupBoxUseWinStyle; //创建groupbox GroupBoxEx box = CreateGroup(pair.Value); //处理当需要将Group置为Dock.Top时的办法(如果置控件的Dock属性是无效的) if (isGroupDockTop) { box.Dock = DockStyle.Top; } //处理控件的语言文本 if (!string.IsNullOrEmpty(groupText)) { if (box.InnerGroupBox != null) { //获得语言文本 box.InnerGroupBox.Text = GetLanguageText( AutoLayoutPanelXmlDocument.Singler, groupText); } } this.Controls.Add(box); } } }//if }