merging the Mainsoft branch to the trunk
[mono.git] / mcs / tools / corcompare / mono-api-info.cs
index b6cb64bab0ea004a070b88f0e0fe4318346de7cc..67a773f5d47b1cdab0212d23f01759a95b8db4b2 100644 (file)
@@ -4,7 +4,7 @@
 // Authors:
 //     Gonzalo Paniagua Javier (gonzalo@ximian.com)
 //
-// (C) 2003 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2003-2005 Novell, Inc (http://www.novell.com)
 //
 
 using System;
@@ -12,6 +12,7 @@ using System.Collections;
 using System.Globalization;
 using System.Reflection;
 using System.Runtime.InteropServices;
+using System.Security.Permissions;
 using System.Text;
 using System.Xml;
 
@@ -142,7 +143,7 @@ namespace Mono.AssemblyInfo
                        AddAttribute (nassembly, "version", aname.Version.ToString ());
                        parent.AppendChild (nassembly);
                        AttributeData.OutputAttributes (document, nassembly, ass.GetCustomAttributes (false));
-                       Type [] types = ass.GetTypes ();
+                       Type [] types = ass.GetExportedTypes ();
                        if (types == null || types.Length == 0)
                                return;
 
@@ -269,6 +270,9 @@ namespace Mono.AssemblyInfo
                        if (type.IsSealed)
                                AddAttribute (nclass, "sealed", "true");
 
+                       if (type.IsAbstract)
+                               AddAttribute (nclass, "abstract", "true");
+
                        if (type.IsSerializable)
                                AddAttribute (nclass, "serializable", "true");
 
@@ -428,7 +432,7 @@ namespace Mono.AssemblyInfo
                        return (FieldInfo[]) list.ToArray (typeof (FieldInfo));
                }
 
-               private PropertyInfo[] GetProperties (Type type)
+               internal static PropertyInfo[] GetProperties (Type type)
                {
                        ArrayList list = new ArrayList ();
 
@@ -762,8 +766,8 @@ namespace Mono.AssemblyInfo
 
                                if (parameter.IsOptional) {
                                        AddAttribute (paramNode, "optional", "true");
-                                       if (parameter.DefaultValue != null)
-                                               AddAttribute (paramNode, "defaultValue", parameter.DefaultValue.ToString ());
+                                       if (parameter.DefaultValue != System.DBNull.Value)
+                                               AddAttribute (paramNode, "defaultValue", (parameter.DefaultValue == null) ? "NULL" : parameter.DefaultValue.ToString ());
                                }
 
                                if (direction != "in")
@@ -805,30 +809,55 @@ namespace Mono.AssemblyInfo
                                parent.AppendChild (natts);
                        }
 
-                       ArrayList typeList = new ArrayList (atts.Length);
-                       string comment = null;
-                       for (int i = atts.Length - 1; i >= 0; i--) {
-                               Type attType = atts [i].GetType ();
-                               if (!MustDocumentAttribute (attType))
+                       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;
-                               typeList.Add (attType);
-                               if (attType.Name.EndsWith ("TODOAttribute")) {
-                                       PropertyInfo prop = attType.GetProperty ("Comment");
-                                       if (prop != null)
-                                               comment = (string) prop.GetValue (atts [i], null);
-                               }
-                       }
 
-                       Type[] types = (Type[]) typeList.ToArray (typeof (Type));
-                       Array.Sort (types, TypeComparer.Default);
-                       foreach (Type t in types) {
                                XmlNode node = document.CreateElement ("attribute");
                                AddAttribute (node, "name", t.FullName);
+
+                               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;
+                                       }
+                               }
+
                                if (target != null) {
                                        AddAttribute (node, "target", target);
                                }
-                               if (comment != null && t.Name.EndsWith ("TODOAttribute"))
-                                       AddAttribute (node, "comment", comment);
 
                                natts.AppendChild (node);
                        }