2
using System.Reflection;
3
using System.Collections.Generic;
7
public static Dictionary<Type, bool> PendingTypes = new Dictionary<Type, bool>();
9
public static int Main(string[] argv)
11
if (argv.Length != 1) {
12
Console.Error.WriteLine("Usage: query full-qualified-name");
16
string name = argv[0];
17
Type t = Type.GetType(name);
19
Console.Error.WriteLine("Cannot load type {0}", name);
24
Console.Error.WriteLine("Cannot load a non-public type");
32
private static void PrintType(Type t)
34
Console.WriteLine("Assembly = '{0}'", t.Assembly.FullName);
35
Console.WriteLine("FullName = '{0}'", t.FullName);
36
Console.WriteLine("BaseType = '{0}'", GetBaseType(t));
37
Console.WriteLine("OOType = '{0}'", GetOOType(t));
38
Console.WriteLine("IsArray = {0}", t.IsArray);
40
Console.WriteLine("ElementType = '{0}'", t.GetElementType().FullName);
41
PrintMethods("StaticMethods", t.GetMethods(BindingFlags.Static|BindingFlags.Public|BindingFlags.DeclaredOnly));
42
PrintMethods("Methods", t.GetMethods(BindingFlags.Instance|BindingFlags.Public|BindingFlags.DeclaredOnly));
43
PendingTypes.Remove(t);
47
private static string GetBaseType(Type t)
49
if (t == typeof(object))
50
return "ROOT"; // special case for System.Object to avoid circular dependencies
51
else if (t.BaseType == null)
52
return "System.Object"; // the only known case is the BaseType of an interface
54
return t.BaseType.FullName;
57
private static string GetOOType(Type t)
61
else if (t == typeof(void))
63
else if (t == typeof(int))
64
return "ootype.Signed";
65
else if (t == typeof(uint))
66
return "ootype.Unsigned";
67
else if (t == typeof(long))
68
return "ootype.SignedLongLong";
69
else if (t == typeof(ulong))
70
return "ootype.UnsignedLongLong";
71
else if (t == typeof(bool))
73
else if (t == typeof(double))
74
return "ootype.Float";
75
else if (t == typeof(char))
76
return "ootype.Char"; // maybe it should be unichar?
77
else if (t == typeof(string))
78
return "ootype.String";
80
PendingTypes[t] = true;
81
string name = t.FullName.Replace(".", "_"); // TODO: ensure unicity
83
name = name.Replace("[]", "___array___");
88
private static void PrintMethods(string varname, MethodInfo[] methods)
90
Console.WriteLine("{0} = [", varname);
91
// MethodName, [ARGS], RESULT
92
foreach(MethodInfo meth in methods) {
93
if (IgnoreMethod(meth))
95
Console.Write(" ('{0}', [", meth.Name);
96
foreach(ParameterInfo par in meth.GetParameters()) {
97
Console.Write("'{0}'", GetOOType(par.ParameterType));
100
Console.WriteLine("], '{0}'),", GetOOType(meth.ReturnType));
102
Console.WriteLine(" ]");
105
private static bool IgnoreMethod(MethodInfo meth)
110
// ignore all SpecialName but properties getter/setter
111
if (meth.IsSpecialName && !meth.Name.StartsWith("get_") && !meth.Name.StartsWith("set_"))
114
if (IgnoreType(meth.ReturnType))
116
foreach(ParameterInfo par in meth.GetParameters())
117
if (IgnoreType(par.ParameterType))
123
private static bool IgnoreType(Type t)
125
return !t.IsPrimitive
127
&&(t == typeof(System.ValueType) ||
128
t == typeof(System.Array) ||
129
t.FullName.StartsWith("System.Array+InternalArray") ||
134
t.IsGenericTypeDefinition);
137
private static void PrintDepend()
139
Console.Write("Depend = [");
140
foreach(Type t in PendingTypes.Keys)
141
Console.Write("'{0}', ", t.FullName);
142
Console.WriteLine("]");