diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala
index 98b2af2..74b5967 100644
--- a/codegen/valagirwriter.vala
+++ b/codegen/valagirwriter.vala
@@ -158,7 +158,7 @@ public class Vala.GIRWriter : CodeVisitor {
 			stream.printf ("<class name=\"%s\"", cl.name);
 			write_gtype_attributes (cl);
 			stream.printf (" glib:type-struct=\"%s\"", gtype_struct_name);
-			stream.printf (" parent=\"%s\"", gi_type_name (cl.base_class));
+			stream.printf (" parent=\"%s\"", gi_type_name (cl.base_class, cl.base_class.get_gir_namespace()));
 			if (cl.is_abstract) {
 				stream.printf (" abstract=\"1\"");
 			}
@@ -746,8 +746,11 @@ public class Vala.GIRWriter : CodeVisitor {
 			write_indent ();
 			stream.printf ("<type name=\"any\" c:type=\"%s\"/>\n", type.get_cname ());
 		} else if (type.data_type != null) {
+			string gi_type;
+
 			write_indent ();
-			stream.printf ("<type name=\"%s\" c:type=\"%s\"", gi_type_name (type.data_type), type.get_cname ());
+			gi_type = gi_type_name (type.data_type, type.data_type.get_gir_namespace());
+			stream.printf ("<type name=\"%s\" c:type=\"%s\"", gi_type, type.get_cname ());
 
 			Gee.List<DataType> type_arguments = type.get_type_arguments ();
 			if (type_arguments.size == 0) {
@@ -787,8 +790,19 @@ public class Vala.GIRWriter : CodeVisitor {
 		}
 	}
 
-	private string gi_type_name (TypeSymbol type_symbol) {
-		return vala_to_gi_type_name (type_symbol.get_full_name());
+	private string gi_type_name (TypeSymbol type_symbol, string? type_gir_ns = null) {
+		Symbol parent = type_symbol.parent_symbol;
+		if (type_gir_ns == null) {
+			if (parent is Namespace) {
+				Namespace ns = parent as Namespace;
+				if (ns.name != null && ns.get_gir_namespace() != null) {
+					return "%s.%s".printf (ns.get_gir_namespace(), type_symbol.name);
+				}
+			}
+			return vala_to_gi_type_name (type_symbol.get_full_name());
+		} else {
+			return "%s.%s".printf (type_gir_ns, type_symbol.name);
+		}
 	}
 
 	private string vala_to_gi_type_name (string name) {
@@ -807,10 +821,6 @@ public class Vala.GIRWriter : CodeVisitor {
 			for (int i = 1; i < split_name.length; i++) {
 				type_name.append (split_name[i]);
 			}
-
-			if (type_name.str == "GLib.Object") {
-				return "GObject.Object";
-			}
 			return type_name.str;
 		}
 	}
diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala
index 55dd513..5db6a88 100644
--- a/vala/valacodewriter.vala
+++ b/vala/valacodewriter.vala
@@ -96,7 +96,25 @@ public class Vala.CodeWriter : CodeVisitor {
 		}
 
 		write_indent ();
-		write_string ("[CCode (cprefix = \"%s\", lower_case_cprefix = \"%s\")]".printf (ns.get_cprefix (), ns.get_lower_case_cprefix ()));
+		write_string ("[CCode (cprefix = \"%s\", lower_case_cprefix = \"%s\"".printf (ns.get_cprefix (), ns.get_lower_case_cprefix ()));
+
+		if (ns.gir_namespace != null || ns.gir_version != null) {
+			write_string(", ");
+
+			if (ns.gir_namespace != null) {
+				write_string ("gir_namespace = \"%s\"".printf (ns.gir_namespace));
+				if (ns.gir_version != null) {
+					write_string (", ");
+				}
+			}
+			if (ns.gir_version != null) {
+				write_string ("gir_version = \"%s\"".printf (ns.gir_version));
+			}
+			write_string (")]");
+			write_newline ();
+		}
+
+		write_string(")]");
 		write_newline ();
 
 		write_attributes (ns);
diff --git a/vala/valanamespace.vala b/vala/valanamespace.vala
index 14f93c4..4afcdd2 100644
--- a/vala/valanamespace.vala
+++ b/vala/valanamespace.vala
@@ -45,6 +45,11 @@ public class Vala.Namespace : Symbol {
 	private Gee.List<Namespace> namespaces = new ArrayList<Namespace> ();
 
 	/**
+	 * The GIR namespace version for the symbol, if a custom one is specified.
+	 */
+	public string? gir_version { get; set; default = null; }
+
+	/**
 	 * Creates a new namespace.
 	 *
 	 * @param name             namespace name
@@ -522,8 +527,14 @@ public class Vala.Namespace : Symbol {
 				cheader_filenames.add (filename);
 			}
 		}
+		if (a.has_argument ("gir_namespace")) {
+			gir_namespace = a.get_string ("gir_namespace");
+		}
+		if (a.has_argument ("gir_version")) {
+			gir_version = a.get_string ("gir_version");
+		}
 	}
-	
+
 	/**
 	 * Process all associated attributes.
 	 */
diff --git a/vala/valasymbol.vala b/vala/valasymbol.vala
index 36d32c5..9ae0d9a 100644
--- a/vala/valasymbol.vala
+++ b/vala/valasymbol.vala
@@ -82,6 +82,23 @@ public abstract class Vala.Symbol : CodeNode {
 	public SymbolAccessibility access { get; set; }
 
 	/**
+	 * The GIR namespace for the symbol, if a custom one is specified.
+	 */
+	public string? gir_namespace { get; set; default = null; }
+
+	/**
+	 * Get the GIR namespace, returning one from the parent symbol if not
+	 * explictly set
+	 */
+	public string? get_gir_namespace() {
+		if (gir_namespace != null)
+			return gir_namespace;
+		else if (parent_symbol != null)
+			return parent_symbol.gir_namespace;
+		return null;
+	}
+
+	/**
 	 * Check if this symbol is just internal API (and therefore doesn't need 
 	 * to be listed in header files for instance) by traversing parent symbols
 	 * and checking their accessibility.
diff --git a/vapi/cairo.vapi b/vapi/cairo.vapi
index d43c852..68bc81a 100644
--- a/vapi/cairo.vapi
+++ b/vapi/cairo.vapi
@@ -20,7 +20,7 @@
  * 	Jürg Billeter <j@bitron.ch>
  */
 
-[CCode (cheader_filename = "cairo.h")]
+[CCode (cheader_filename = "cairo.h", gir_namespace = "cairo", gir_version = "1.0")]
 namespace Cairo {
 	[Compact]
 	[CCode (ref_function = "cairo_reference", unref_function = "cairo_destroy", cname = "cairo_t", cprefix = "cairo_", cheader_filename = "cairo.h")]
diff --git a/vapi/gdk-pixbuf-2.0.vapi b/vapi/gdk-pixbuf-2.0.vapi
index ddef2b5..a7fc02e 100644
--- a/vapi/gdk-pixbuf-2.0.vapi
+++ b/vapi/gdk-pixbuf-2.0.vapi
@@ -1,6 +1,6 @@
 /* gdk-pixbuf-2.0.vapi generated by vapigen, do not modify. */
 
-[CCode (cprefix = "Gdk", lower_case_cprefix = "gdk_")]
+[CCode (cprefix = "Gdk", lower_case_cprefix = "gdk_", gir_namespace = "GdkPixbuf", gir_version = "2.0")]
 namespace Gdk {
 	[CCode (cheader_filename = "gdk-pixbuf/gdk-pixdata.h")]
 	public class Pixbuf : GLib.Object {
diff --git a/vapi/gobject-2.0.vapi b/vapi/gobject-2.0.vapi
index 09b0e96..5cc8833 100644
--- a/vapi/gobject-2.0.vapi
+++ b/vapi/gobject-2.0.vapi
@@ -24,7 +24,7 @@
  *	Mathias Hasselmann <mathias.hasselmann@gmx.de>
  */
 
-[CCode (cprefix = "G", lower_case_cprefix = "g_", cheader_filename = "glib.h")]
+[CCode (cprefix = "G", lower_case_cprefix = "g_", cheader_filename = "glib.h", gir_namespace = "GObject", gir_version = "2.0")]
 namespace GLib {
 	[CCode (type_id = "G_TYPE_GTYPE", marshaller_type_name = "GTYPE", get_value_function = "g_value_get_gtype", set_value_function = "g_value_set_gtype")]
 	public struct Type : ulong {
diff --git a/vapi/packages/gdk-pixbuf-2.0/gdk-pixbuf-2.0.metadata b/vapi/packages/gdk-pixbuf-2.0/gdk-pixbuf-2.0.metadata
index e9bf222..fc2b616 100644
--- a/vapi/packages/gdk-pixbuf-2.0/gdk-pixbuf-2.0.metadata
+++ b/vapi/packages/gdk-pixbuf-2.0/gdk-pixbuf-2.0.metadata
@@ -1,4 +1,4 @@
-Gdk cheader_filename="gdk-pixbuf/gdk-pixdata.h"
+Gdk cheader_filename="gdk-pixbuf/gdk-pixdata.h" gir_namespace="GdkPixbuf" gir_version="2.0"
 gdk_pixbuf_copy transfer_ownership="1"
 gdk_pixbuf_get_file_info.width is_out="1"
 gdk_pixbuf_get_file_info.height is_out="1"
diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala
index e8ee349..1beb9b4 100644
--- a/vapigen/valagidlparser.vala
+++ b/vapigen/valagidlparser.vala
@@ -220,6 +220,10 @@ public class Vala.GIdlParser : CodeVisitor {
 					}
 				} else if (nv[0] == "lower_case_cprefix") {
 					ns.set_lower_case_cprefix (eval (nv[1]));
+				} else if (nv[0] == "gir_namespace") {
+					ns.gir_namespace = eval (nv[1]);
+				} else if (nv[0] == "gir_version") {
+					ns.gir_version = eval (nv[1]);
 				}
 			}
 		}
