Hello, So I was thinking last night that it would be pretty nice if assemblies could register things to be called when Application.Init is called. It would be useful for things like initializing gettext catalogs and the like. So here's a patch that adds a GLib.AssemblyInitializerAttribute, which Gtk.Application.Init then uses to call init methods. It's a bit crack rock :)
James
Index: gtk/Application.cs
===================================================================
--- gtk/Application.cs (revision 46265)
+++ gtk/Application.cs (working copy)
@@ -18,6 +18,9 @@
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
+using System;
+using System.Reflection;
+
namespace Gtk {
using System;
@@ -45,6 +48,19 @@
int argc = 0;
gtk_init (ref argc, ref argv);
+
+ foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies ())
+ {
+ GLib.AssemblyInitializerAttribute[] attrs = (GLib.AssemblyInitializerAttribute[]) asm.GetCustomAttributes (typeof (GLib.AssemblyInitializerAttribute), true);
+
+ if (attrs == null || attrs.Length == 0)
+ continue;
+
+ foreach (GLib.AssemblyInitializerAttribute attr in attrs)
+ {
+ attr.Invoke ();
+ }
+ }
}
static bool do_init (string progname, ref string[] args, bool check)
Index: glib/AssemblyInitializerAttribute.cs
===================================================================
--- glib/AssemblyInitializerAttribute.cs (revision 0)
+++ glib/AssemblyInitializerAttribute.cs (revision 0)
@@ -0,0 +1,33 @@
+using System;
+using System.Reflection;
+
+namespace GLib
+{
+ public class AssemblyInitializerAttribute : Attribute
+ {
+ private Type cls;
+ private string method;
+
+ public Type Class
+ {
+ get { return cls; }
+ set { cls = value; }
+ }
+
+ public string Method
+ {
+ get { return method; }
+ set { method = value; }
+ }
+
+ public void Invoke ()
+ {
+ MethodInfo info = cls.GetMethod (method);
+
+ if (info == null)
+ return;
+
+ info.Invoke (null, null);
+ }
+ }
+}
Index: glib/Makefile.am
===================================================================
--- glib/Makefile.am (revision 46265)
+++ glib/Makefile.am (working copy)
@@ -10,6 +10,7 @@
references =
sources = \
+ AssemblyInitializerAttribute.cs \
Argv.cs \
Boxed.cs \
CDeclCallbackAttribute.cs \
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Gtk-sharp-list maillist - [email protected] http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
