[Mono-docs-list] Updating class library docs
Joshua Tauberer
tauberer@for.net
Wed, 03 Mar 2004 09:52:31 -0500
This is a multi-part message in MIME format.
--------------070504020301040404050100
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Ben Maurer wrote:
> Were any docs lost?
No. Two properties were IMO rightfully removed- private ICollection
implementations. (Though other private ICollection impls seemed to stay.)
Hector E. Gomez Morales wrote:
> I think Ben has a very good point, there is not much case to update only
> a part of the class libs, god knows how many links between docs are
> broken, etc.
Good point.
> You comment you have a modified stub.cs could you please
> post the file or the diff against the one you send me?
The changes since the last version:
Methods that implement interfaces or override base class methods are
not added into the docs. I wanted to keep the size of the diff down,
but this might be a mistake.
The program would fail in a few cases on interfaces/System.Object
because they have no BaseType.
Delegate return values weren't working.
Nested types caused an exception.
For some reason typeof(System.Enum).IsClass is false. I added a hack.
Non-virtual interface implementation methods evidentally are "virtual
sealed." Signatures now show them without those modifiers.
And a diff is attached.
--
- Joshua Tauberer
http://taubz.for.net
** Nothing Unreal Exists **
--------------070504020301040404050100
Content-Type: text/x-patch;
name="stub.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="stub.diff"
--- stub.cs.1 2004-03-03 09:42:51.000000000 -0500
+++ stub.cs 2004-03-02 22:50:46.000000000 -0500
@@ -1,3 +1,8 @@
+/*
+ my quick-update-files command:
+ ls corlib-backup/en/System | s -e "(.*)\.xml" "'echo ' . #0 . '; sh ../browser/stub.sh corlib-backup/en corlib/en System ' . #0" | sh &> changes
+*/
+
using System;
using System.Collections;
using System.Text;
@@ -78,11 +83,26 @@
seenmembers[oldmember2] = 1;
}
+ if (!IsDelegate(type)) {
+ Hashtable overrides = new Hashtable();
+ foreach (Type i in type.GetInterfaces())
+ foreach (MethodInfo m in type.GetInterfaceMap(i).TargetMethods)
+ overrides[m] = 1;
+
XmlNode members = basefile.SelectSingleNode("Type/Members");
foreach (MemberInfo m in type.GetMembers(BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Static|BindingFlags.Instance|BindingFlags.DeclaredOnly)) {
if (m is Type) continue;
if (seenmembers.ContainsKey(m)) continue;
+ // To be nice on diffs, members/properties/events that are overrides or are interface implementations
+ // are not added in.
+ if (m is MethodInfo && !IsNew(overrides, (MethodInfo)m)) continue;
+ if (m is PropertyInfo && !IsNew(overrides, ((PropertyInfo)m).GetGetMethod())) continue;
+ if (m is PropertyInfo && !IsNew(overrides, ((PropertyInfo)m).GetSetMethod())) continue;
+ if (m is EventInfo && !IsNew(overrides, ((EventInfo)m).GetAddMethod())) continue;
+ if (m is EventInfo && !IsNew(overrides, ((EventInfo)m).GetRaiseMethod())) continue;
+ if (m is EventInfo && !IsNew(overrides, ((EventInfo)m).GetRemoveMethod())) continue;
+
XmlElement mm = MakeMember(m);
if (mm == null) continue;
members.AppendChild( basefile.ImportNode(mm, true) );
@@ -90,11 +110,19 @@
Console.Error.WriteLine("Member Added: " + mm.SelectSingleNode("MemberSignature/@Value").InnerText);
}
-
+ }
WriteXml(basefile.DocumentElement, Console.Out);
}
+ private static bool IsNew(Hashtable overrides, MethodInfo m) {
+ if (m == null) return true;
+ if (overrides.ContainsKey(m)) return false;
+ MethodInfo b = m.GetBaseDefinition();
+ if (b == null || b == m) return true;
+ return false;
+ }
+
public static void DoRegenType(string basepath, string typename) {
Type type = Type.GetType(typename, true);
@@ -197,9 +225,11 @@
XmlElement assattributes = MakeAttributes(type.Assembly);
if (assattributes != null) ass.AppendChild(assattributes);
+ if (type.BaseType != null) {
XmlElement basetype = doc.CreateElement("Base");
root.AppendChild(basetype);
basetype.AppendChild(SimpleElement("BaseTypeName", type.BaseType.FullName));
+ }
if (!IsDelegate(type) && !type.IsInterface) {
XmlElement interfaces = doc.CreateElement("Interfaces");
@@ -216,7 +246,7 @@
if (IsDelegate(type)) {
root.AppendChild(MakeParameters(type.GetMethod("Invoke").GetParameters()));
- root.AppendChild(MakeReturnValue(type.GetMethod("Invoke").ReturnType));
+ root.AppendChild(MakeReturnValue(type.GetMethod("Invoke")));
}
if (!IsDelegate(type)) {
@@ -351,10 +381,12 @@
if (mi is PropertyInfo) return MakeReturnValue(((PropertyInfo)mi).PropertyType, null);
if (mi is FieldInfo) return MakeReturnValue(((FieldInfo)mi).FieldType, null);
if (mi is EventInfo) return MakeReturnValue(((EventInfo)mi).EventHandlerType, null);
- throw new ArgumentException();
+ throw new ArgumentException(mi.GetType().FullName);
}
private static XmlElement MakeMember(MemberInfo mi) {
+ if (mi is Type) return null;
+
string sigs = MakeMemberSignature(mi);
if (sigs == null) return null; // not publicly visible
@@ -386,8 +418,11 @@
if (mi is FieldInfo && (((FieldInfo)mi).IsLiteral || (((FieldInfo)mi).IsStatic && ((FieldInfo)mi).IsInitOnly))) {
object val = ((FieldInfo)mi).GetValue(null);
- if (val is IConvertible)
- me.AppendChild( SimpleElement("MemberValue", ((IConvertible)val).ToString(null)) );
+ if (val == null) val = "null";
+ else if (val is Enum) val = val.ToString();
+ else if (val is IFormattable) val = ((IConvertible)val).ToString(null);
+ if (val is string && (string)val != "")
+ me.AppendChild( SimpleElement("MemberValue", (string)val) );
}
if (mi is MethodInfo)
@@ -410,10 +445,10 @@
static string GetTypeKind (Type t) {
if (t.IsEnum) return "enum";
- if (t.IsClass) return "class";
+ if (t.IsClass || t == typeof(System.Enum)) return "class";
if (t.IsInterface) return "interface";
if (t.IsValueType) return "struct";
- throw new ArgumentException();
+ throw new ArgumentException(t.FullName);
}
static string GetTypeVisibility (TypeAttributes ta) {
@@ -544,6 +579,7 @@
}
if (method.IsAbstract) modifiers += " abstract";
if (method.IsFinal) modifiers += " sealed";
+ if (modifiers == " virtual sealed") modifiers = "";
string return_type = ConvertCTSName (method.ReturnType.FullName);
string parameters = GetMethodParameters (method.GetParameters());
@@ -587,6 +623,7 @@
}
if (method.IsAbstract) modifiers += " abstract";
if (method.IsFinal) modifiers += " sealed";
+ if (modifiers == " virtual sealed") modifiers = "";
string name = property.Name;
@@ -623,6 +660,7 @@
}
if (add.IsAbstract) modifiers += " abstract";
if (add.IsFinal) modifiers += " sealed";
+ if (modifiers == " virtual sealed") modifiers = "";
string name = ev.Name;
string type = ConvertCTSName(ev.EventHandlerType.FullName);
--------------070504020301040404050100--