public override void DoOutput() { if (document == null) { throw new InvalidOperationException("Document not set"); } XmlNode nclass = document.CreateElement("class", null); AddAttribute(nclass, "name", type.Name); string classType = GetClassType(type); AddAttribute(nclass, "type", classType); if (type.BaseType != null) { AddAttribute(nclass, "base", type.BaseType.ToString()); } if (type.IsSealed) { AddAttribute(nclass, "sealed", "true"); } if (type.IsAbstract) { AddAttribute(nclass, "abstract", "true"); } if (type.IsSerializable) { AddAttribute(nclass, "serializable", "true"); } string charSet = GetCharSet(type); AddAttribute(nclass, "charset", charSet); string layout = GetLayout(type); if (layout != null) { AddAttribute(nclass, "layout", layout); } parent.AppendChild(nclass); AttributeData.OutputAttributes(document, nclass, type.GetCustomAttributes(false)); Type [] interfaces = type.GetInterfaces(); if (interfaces != null && interfaces.Length > 0) { XmlNode ifaces = document.CreateElement("interfaces", null); nclass.AppendChild(ifaces); foreach (Type t in interfaces) { if (!t.IsPublic) { // we're only interested in public interfaces continue; } XmlNode iface = document.CreateElement("interface", null); AddAttribute(iface, "name", t.ToString()); ifaces.AppendChild(iface); } } #if NET_2_0 // Generic constraints Type [] gargs = type.GetGenericArguments(); XmlElement ngeneric = (gargs.Length == 0) ? null : document.CreateElement("generic-type-constraints"); foreach (Type garg in gargs) { Type [] csts = garg.GetGenericParameterConstraints(); if (csts.Length == 0 || csts [0] == typeof(object)) { continue; } XmlElement el = document.CreateElement("generic-type-constraint"); el.SetAttribute("name", garg.ToString()); el.SetAttribute("generic-attribute", garg.GenericParameterAttributes.ToString()); ngeneric.AppendChild(el); foreach (Type ct in csts) { XmlElement cel = document.CreateElement("type"); cel.AppendChild(document.CreateTextNode(ct.FullName)); el.AppendChild(cel); } } if (ngeneric != null && ngeneric.FirstChild != null) { nclass.AppendChild(ngeneric); } #endif ArrayList members = new ArrayList(); FieldInfo[] fields = GetFields(type); if (fields.Length > 0) { Array.Sort(fields, MemberInfoComparer.Default); FieldData fd = new FieldData(document, nclass, fields); // Special case for enum fields if (classType == "enum") { string etype = fields [0].GetType().ToString(); AddAttribute(nclass, "enumtype", etype); } members.Add(fd); } ConstructorInfo [] ctors = GetConstructors(type); if (ctors.Length > 0) { Array.Sort(ctors, MemberInfoComparer.Default); members.Add(new ConstructorData(document, nclass, ctors)); } PropertyInfo[] properties = GetProperties(type); if (properties.Length > 0) { Array.Sort(properties, MemberInfoComparer.Default); members.Add(new PropertyData(document, nclass, properties)); } EventInfo [] events = GetEvents(type); if (events.Length > 0) { Array.Sort(events, MemberInfoComparer.Default); members.Add(new EventData(document, nclass, events)); } MethodInfo [] methods = GetMethods(type); if (methods.Length > 0) { Array.Sort(methods, MemberInfoComparer.Default); members.Add(new MethodData(document, nclass, methods)); } foreach (MemberData md in members) { md.DoOutput(); } Type [] nested = type.GetNestedTypes(); if (nested != null && nested.Length > 0) { XmlNode classes = document.CreateElement("classes", null); nclass.AppendChild(classes); foreach (Type t in nested) { TypeData td = new TypeData(document, classes, t); td.DoOutput(); } } }
public override void DoOutput() { if (document == null) { throw new InvalidOperationException("Document not set"); } XmlNode nassembly = document.CreateElement("assembly", null); AssemblyName aname = ass.GetName(); AddAttribute(nassembly, "name", aname.Name); AddAttribute(nassembly, "version", aname.Version.ToString()); parent.AppendChild(nassembly); AttributeData.OutputAttributes(document, nassembly, ass.GetCustomAttributes(false)); Type [] types = ass.GetExportedTypes(); if (types == null || types.Length == 0) { return; } Array.Sort(types, TypeComparer.Default); XmlNode nss = document.CreateElement("namespaces", null); nassembly.AppendChild(nss); string currentNS = "$%&$&"; XmlNode ns = null; XmlNode classes = null; foreach (Type t in types) { if (t.Namespace == null || t.Namespace == "") { continue; } if (t.IsNotPublic) { continue; } if (t.IsNestedPublic || t.IsNestedAssembly || t.IsNestedFamANDAssem || t.IsNestedFamORAssem || t.IsNestedPrivate) { continue; } if (t.DeclaringType != null) { continue; // enforce !nested } if (t.Namespace != currentNS) { currentNS = t.Namespace; ns = document.CreateElement("namespace", null); AddAttribute(ns, "name", currentNS); nss.AppendChild(ns); classes = document.CreateElement("classes", null); ns.AppendChild(classes); } TypeData bd = new TypeData(document, classes, t); bd.DoOutput(); } }
public override void DoOutput() { if (document == null) throw new InvalidOperationException ("Document not set"); XmlNode nclass = document.CreateElement ("class", null); AddAttribute (nclass, "name", type.Name); string classType = GetClassType (type); AddAttribute (nclass, "type", classType); if (type.BaseType != null) AddAttribute (nclass, "base", type.BaseType.ToString ()); if (type.IsSealed) AddAttribute (nclass, "sealed", "true"); if (type.IsAbstract) AddAttribute (nclass, "abstract", "true"); if (type.IsSerializable) AddAttribute (nclass, "serializable", "true"); string charSet = GetCharSet (type); AddAttribute (nclass, "charset", charSet); string layout = GetLayout (type); if (layout != null) AddAttribute (nclass, "layout", layout); parent.AppendChild (nclass); AttributeData.OutputAttributes (document, nclass, type.GetCustomAttributes (false)); Type [] interfaces = type.GetInterfaces (); if (interfaces != null && interfaces.Length > 0) { XmlNode ifaces = document.CreateElement ("interfaces", null); nclass.AppendChild (ifaces); foreach (Type t in interfaces) { if (!t.IsPublic) { // we're only interested in public interfaces continue; } XmlNode iface = document.CreateElement ("interface", null); AddAttribute (iface, "name", t.ToString ()); ifaces.AppendChild (iface); } } #if NET_2_0 // Generic constraints Type [] gargs = type.GetGenericArguments (); XmlElement ngeneric = (gargs.Length == 0) ? null : document.CreateElement ("generic-type-constraints"); foreach (Type garg in gargs) { Type [] csts = garg.GetGenericParameterConstraints (); if (csts.Length == 0 || csts [0] == typeof (object)) continue; XmlElement el = document.CreateElement ("generic-type-constraint"); el.SetAttribute ("name", garg.ToString ()); el.SetAttribute ("generic-attribute", garg.GenericParameterAttributes.ToString ()); ngeneric.AppendChild (el); foreach (Type ct in csts) { XmlElement cel = document.CreateElement ("type"); cel.AppendChild (document.CreateTextNode (ct.FullName)); el.AppendChild (cel); } } if (ngeneric != null && ngeneric.FirstChild != null) nclass.AppendChild (ngeneric); #endif ArrayList members = new ArrayList (); FieldInfo[] fields = GetFields (type); if (fields.Length > 0) { Array.Sort (fields, MemberInfoComparer.Default); FieldData fd = new FieldData (document, nclass, fields); // Special case for enum fields if (classType == "enum") { string etype = fields [0].GetType ().ToString (); AddAttribute (nclass, "enumtype", etype); } members.Add (fd); } ConstructorInfo [] ctors = GetConstructors (type); if (ctors.Length > 0) { Array.Sort (ctors, MemberInfoComparer.Default); members.Add (new ConstructorData (document, nclass, ctors)); } PropertyInfo[] properties = GetProperties (type); if (properties.Length > 0) { Array.Sort (properties, MemberInfoComparer.Default); members.Add (new PropertyData (document, nclass, properties)); } EventInfo [] events = GetEvents (type); if (events.Length > 0) { Array.Sort (events, MemberInfoComparer.Default); members.Add (new EventData (document, nclass, events)); } MethodInfo [] methods = GetMethods (type); if (methods.Length > 0) { Array.Sort (methods, MemberInfoComparer.Default); members.Add (new MethodData (document, nclass, methods)); } foreach (MemberData md in members) md.DoOutput (); Type [] nested = type.GetNestedTypes (); if (nested != null && nested.Length > 0) { XmlNode classes = document.CreateElement ("classes", null); nclass.AppendChild (classes); foreach (Type t in nested) { TypeData td = new TypeData (document, classes, t); td.DoOutput (); } } }
public override void DoOutput() { if (document == null) { throw new InvalidOperationException("Document not set"); } if (atts == null || atts.Length == 0) { return; } XmlNode natts = parent.SelectSingleNode("attributes"); if (natts == null) { natts = document.CreateElement("attributes", null); parent.AppendChild(natts); } for (int i = 0; i < atts.Length; ++i) { Type t = atts [i].GetType(); if (!t.IsPublic && !t.Name.EndsWith("TODOAttribute")) { continue; } // we ignore attributes that inherit from SecurityAttribute on purpose as they: // * aren't part of GetCustomAttributes in Fx 1.0/1.1; // * are encoded differently and in a different metadata table; and // * won't ever exactly match MS implementation (from a syntax pov) if (t.IsSubclassOf(typeof(SecurityAttribute))) { continue; } XmlNode node = document.CreateElement("attribute"); AddAttribute(node, "name", t.ToString()); XmlNode properties = null; foreach (PropertyInfo pi in TypeData.GetProperties(t)) { if (pi.Name == "TypeId") { continue; } if (properties == null) { properties = node.AppendChild(document.CreateElement("properties")); } try { object o = pi.GetValue(atts [i], null); XmlNode n = properties.AppendChild(document.CreateElement("property")); AddAttribute(n, "name", pi.Name); if (o == null) { AddAttribute(n, "null", "true"); continue; } string value = o.ToString(); if (t == typeof(GuidAttribute)) { value = value.ToUpper(); } AddAttribute(n, "value", value); } catch (TargetInvocationException) { continue; } } natts.AppendChild(node); } }
public override void DoOutput() { if (document == null) throw new InvalidOperationException ("Document not set"); XmlNode nassembly = document.CreateElement ("assembly", null); AssemblyName aname = ass.GetName (); AddAttribute (nassembly, "name", aname.Name); AddAttribute (nassembly, "version", aname.Version.ToString ()); parent.AppendChild (nassembly); AttributeData.OutputAttributes (document, nassembly, ass.GetCustomAttributes (false)); Type [] types = ass.GetExportedTypes (); if (types == null || types.Length == 0) return; Array.Sort (types, TypeComparer.Default); XmlNode nss = document.CreateElement ("namespaces", null); nassembly.AppendChild (nss); string currentNS = "$%&$&"; XmlNode ns = null; XmlNode classes = null; foreach (Type t in types) { if (t.Namespace == null || t.Namespace == "") continue; if (t.IsNotPublic) continue; if (t.IsNestedPublic || t.IsNestedAssembly || t.IsNestedFamANDAssem || t.IsNestedFamORAssem || t.IsNestedPrivate) continue; if (t.DeclaringType != null) continue; // enforce !nested if (t.Namespace != currentNS) { currentNS = t.Namespace; ns = document.CreateElement ("namespace", null); AddAttribute (ns, "name", currentNS); nss.AppendChild (ns); classes = document.CreateElement ("classes", null); ns.AppendChild (classes); } TypeData bd = new TypeData (document, classes, t); bd.DoOutput (); } }