[Gtk-sharp-list] GLib.List and SList in public API

John Luke john.luke@gmail.com
Tue, 25 Jan 2005 18:40:03 -0500


--=-VPAahlTYNCQLxI9VUV/w
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hello,
	I wrote a quick reflection-based tool to identify parts of Gtk# and
related assemblies that expose either GLib.List or GLib.SList as part of
the public API. Typically we convert this to a more specific array type
(ex. Gtk.Widget[]) via .custom modifications.  Perhaps it occurs often
enough to fix in the generator?

Anyways, this is mostly just to help identify them, for people to fix if
they want to (external bindings also).

use like:
mcs PrintGlist.cs -pkg:gtk-sharp-2.0
mono PrintGlist.exe gtk-sharp.dll gnome-sharp.dll etc.




--=-VPAahlTYNCQLxI9VUV/w
Content-Disposition: attachment; filename=PrintGList.cs
Content-Type: text/x-csharp; name=PrintGList.cs; charset=UTF-8
Content-Transfer-Encoding: 7bit

using System;
using System.IO;
using System.Reflection;

class PrintGList
{
	static BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;
	static Type currentType;

	static void Main (string[] args)
	{
		foreach (string s in args)
		{
			if (File.Exists (s))
				Print (s);
		}
	}

	static void Print (string file)
	{
		Console.WriteLine ("checking {0}:", file);
		Assembly a = Assembly.LoadFrom (file);

		// only check public types
		Type[] types = a.GetExportedTypes ();

		foreach (Type t in types)
			PrintType (t);

		Console.WriteLine ();
	}

	static void PrintType (Type type)
	{
		// cache this for printing the whole name
		currentType = type;

		FieldInfo[] fields = type.GetFields (flags);
		foreach (FieldInfo fi in fields)
			CheckField (fi);

		ConstructorInfo[] constructors = type.GetConstructors (flags);
		foreach (ConstructorInfo ci in constructors)
			CheckConstructor (ci);

		MethodInfo[] methods = type.GetMethods (flags);
		foreach (MethodInfo mi in methods)
			CheckMethod (mi);

		PropertyInfo[] properties = type.GetProperties (flags);
		foreach (PropertyInfo pi in properties)
			CheckProperty (pi);
	}

	static void CheckConstructor (ConstructorInfo constructor)
	{
		ParameterInfo[] parameters = constructor.GetParameters ();
		foreach (ParameterInfo pi in parameters)
		{
			if (pi.ParameterType == typeof (GLib.List) || pi.ParameterType == typeof (GLib.SList))
				Console.WriteLine ("{0}.{1}", currentType.FullName, constructor.Name);
		}	
	}

	static void CheckField (FieldInfo field)
	{
		if (field.FieldType == typeof (GLib.List) || field.FieldType == typeof (GLib.SList))
			Console.WriteLine ("{0}.{1}", currentType.FullName, field.Name);
	}

	static void CheckMethod (MethodInfo method)
	{
		if (method.IsSpecialName)
			return;

		if (method.ReturnType == typeof (GLib.List) || method.ReturnType == typeof (GLib.SList))
			Console.WriteLine ("{0}.{1}", currentType.FullName, method.Name);

		ParameterInfo[] parameters = method.GetParameters ();
		foreach (ParameterInfo pi in parameters)
		{
			if (pi.ParameterType == typeof (GLib.List) || pi.ParameterType == typeof (GLib.SList))
				Console.WriteLine ("{0}.{1}", currentType.FullName, method.Name);
		}	
	}

	static void CheckProperty (PropertyInfo property)
	{
		if (property.PropertyType == typeof (GLib.List) || property.PropertyType == typeof (GLib.SList))
			Console.WriteLine ("{0}.{1}", currentType.FullName, property.Name);
	}
}


--=-VPAahlTYNCQLxI9VUV/w--