+2005-01-22 Ben Maurer <bmaurer@ximian.com>
+
+ * options.cs: Make things public.
+
+ * outline.cs: Use the Options class, rather than being passed
+ binding flags.
+ (.ctor): Add Options param
+ (OutlineType): remove bindingFlags param
+ (DefaultFlags): Get the correct binding flags
+ (ShowMember): Return true if we should show this member given the
+ Options. Way too long due to MSFT stupidity.
+ (OutlineType): call the above.
+
+ * monop.cs (Main): Don't fiddle with binding flags ourselves.
+
+
2005-01-08 John Luke <john.luke@gmail.com>
* monop.cs: use Options class
class MonoP {
static string assembly;
- static BindingFlags default_flags =
- BindingFlags.Instance |
- BindingFlags.Static |
- BindingFlags.Public;
// very common namespaces, all in corlib
static readonly string [] v_common_ns = {
Options options = new Options ();
if (!options.ProcessArgs (args))
return;
-
- if (options.ShowPrivate)
- default_flags |= BindingFlags.NonPublic;
-
- if (options.DeclaredOnly)
- default_flags |= BindingFlags.DeclaredOnly;
if (options.AssemblyReference != null) {
assembly = options.AssemblyReference;
// This gets us nice buffering
//
StreamWriter sw = new StreamWriter (Console.OpenStandardOutput (), Console.Out.Encoding);
- new Outline (t, sw).OutlineType (default_flags);
+ new Outline (t, sw, options).OutlineType ();
sw.Flush ();
if (message != null)
public class Outline {
+ Options options;
IndentedTextWriter o;
Type t;
- public Outline (Type t, TextWriter output)
+ public Outline (Type t, TextWriter output, Options options)
{
this.t = t;
this.o = new IndentedTextWriter (output, " ");
+ this.options = options;
}
- public void OutlineType (BindingFlags flags)
+ public void OutlineType ()
{
bool first;
first = true;
- foreach (ConstructorInfo ci in t.GetConstructors (flags)) {
+ foreach (ConstructorInfo ci in t.GetConstructors (DefaultFlags)) {
+
+ if (! ShowMember (ci))
+ continue;
+
if (first)
o.WriteLine ();
first = false;
first = true;
- foreach (MethodInfo m in Comparer.Sort (t.GetMethods (flags))) {
+ foreach (MethodInfo m in Comparer.Sort (t.GetMethods (DefaultFlags))) {
+
+ if (! ShowMember (m))
+ continue;
+
if ((m.Attributes & MethodAttributes.SpecialName) != 0)
continue;
first = true;
- foreach (MethodInfo m in t.GetMethods (flags)) {
+ foreach (MethodInfo m in t.GetMethods (DefaultFlags)) {
+
+ if (! ShowMember (m))
+ continue;
+
if ((m.Attributes & MethodAttributes.SpecialName) == 0)
continue;
if (!(m.Name.StartsWith ("op_")))
first = true;
- foreach (PropertyInfo pi in Comparer.Sort (t.GetProperties (flags))) {
+ foreach (PropertyInfo pi in Comparer.Sort (t.GetProperties (DefaultFlags))) {
+
+ if (! ((pi.CanRead && ShowMember (pi.GetGetMethod (true))) ||
+ (pi.CanWrite && ShowMember (pi.GetSetMethod (true)))))
+ continue;
if (first)
o.WriteLine ();
first = true;
- foreach (FieldInfo fi in t.GetFields (flags)) {
+ foreach (FieldInfo fi in t.GetFields (DefaultFlags)) {
+
+ if (! ShowMember (fi))
+ continue;
if (first)
o.WriteLine ();
first = true;
- foreach (EventInfo ei in Comparer.Sort (t.GetEvents (flags))) {
+ foreach (EventInfo ei in Comparer.Sort (t.GetEvents (DefaultFlags))) {
+
+ if (! ShowMember (ei.GetAddMethod ()))
+ continue;
if (first)
o.WriteLine ();
first = true;
- foreach (Type ntype in Comparer.Sort (t.GetNestedTypes (flags))) {
+ foreach (Type ntype in Comparer.Sort (t.GetNestedTypes (DefaultFlags))) {
+
+ if (! ShowMember (ntype))
+ continue;
if (first)
o.WriteLine ();
first = false;
- new Outline (ntype, o).OutlineType (flags);
+ new Outline (ntype, o, options).OutlineType ();
}
o.Indent--; o.WriteLine ("}");
}
+
+ BindingFlags DefaultFlags {
+ get {
+ BindingFlags f = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
+
+ if (options.DeclaredOnly)
+ f |= BindingFlags.DeclaredOnly;
+
+ return f;
+ }
+ }
// FIXME: add other interesting attributes?
void OutlineAttributes ()
default: return name;
}
}
+
+ bool ShowMember (MemberInfo mi)
+ {
+ if (options.ShowPrivate)
+ return true;
+
+ switch (mi.MemberType) {
+ case MemberTypes.Constructor:
+ case MemberTypes.Method:
+ MethodBase mb = mi as MethodBase;
+
+ if (mb.IsFamily || mb.IsPublic || mb.IsFamilyOrAssembly)
+ return true;
+
+ return false;
+
+
+ case MemberTypes.Field:
+ FieldInfo fi = mi as FieldInfo;
+
+ if (fi.IsFamily || fi.IsPublic || fi.IsFamilyOrAssembly)
+ return true;
+
+ return false;
+
+
+ case MemberTypes.NestedType:
+ case MemberTypes.TypeInfo:
+ Type t = mi as Type;
+
+ switch (t.Attributes & TypeAttributes.VisibilityMask){
+ case TypeAttributes.Public:
+ case TypeAttributes.NestedPublic:
+ case TypeAttributes.NestedFamily:
+ case TypeAttributes.NestedFamORAssem:
+ return true;
+ }
+
+ return false;
+ }
+
+ // What am I !!!
+ return true;
+ }
}
public class Comparer : IComparer {