static VEObjectAsm() { Assembly asm = Assembly.GetAssembly(VEObjectBaseType); Type[] alltypes = asm.GetTypes(); VEObjectTypes = new List <Type> (); foreach (Type t in alltypes) { if (t.IsSubclassOf(VEObjectBaseType)) { if (!t.IsAbstract) { VEObjectTypes.Add(t); } } } TypeDict = new Dictionary <string, XMLMemberCollection> (); foreach (Type t in VEObjectTypes) { XMLMemberCollection mc = new XMLMemberCollection(); mc.Name = t.Name.ToUpper(); TypeDict[t.FullName] = mc; object[] xmlobj_attrs = t.GetCustomAttributes(typeof(XMLObjectAttribute), false); if (xmlobj_attrs.Length > 0) { mc.Name = (xmlobj_attrs[0] as XMLObjectAttribute).Name.ToUpper(); } MemberInfo[] mems = t.GetMembers(); foreach (MemberInfo mem in mems) { FieldInfo field = mem as FieldInfo; PropertyInfo property = mem as PropertyInfo; if (field != null || property != null) { object[] xml_attrs = mem.GetCustomAttributes(typeof(XMLIOAttribute), true); XMLIOAttribute xmlAttr = (xml_attrs.Length > 0) ? (xml_attrs[0] as XMLIOAttribute) : (null); if (xmlAttr != null) { XMLMemberDesc xmlDesc = new XMLMemberDesc(); xmlDesc.Name = mem.Name; xmlDesc.Type = (field != null) ? field.FieldType : property.PropertyType; xmlDesc.Field = field; xmlDesc.Property = property; xmlDesc.Order = xmlAttr.Order; xmlDesc.Attr = xmlAttr.Attr; xmlDesc.Necessary = xmlAttr.Necessary; xmlDesc.DefaultValue = xmlAttr.DefaultValue; mc.Members.Add(xmlDesc); } } } mc.Members.Sort(XMLMemberDesc.Compare); } }
public static int Compare(XMLMemberDesc lhs, XMLMemberDesc rhs) { return(lhs.Order - rhs.Order); }