Exemple #1
0
        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();
                }
            }
        }
Exemple #2
0
        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 ();
                }
            }
        }