public static GLib.GType GetThresholdType(this GLib.GType gtype) { GLib.GType curr = gtype; while (curr.ToString().StartsWith("__gtksharp_")) { curr = GetBaseType(curr); } return(curr); }
public TypedClassDescriptor(Assembly assembly, XmlElement elem) { bool inheritedWrapper = false; wrapped = Registry.GetType(elem.GetAttribute("type"), true); if (wrapped != null) { ConstructorInfo[] cInfos = wrapped.GetConstructors(); foreach (ConstructorInfo ci in cInfos) { if (ci.GetParameters().Length == 0) { cinfoNoParams = ci; break; } } } if (elem.HasAttribute("wrapper")) { wrapper = Registry.GetType(elem.GetAttribute("wrapper"), true); } else { inheritedWrapper = true; string baseClass = elem.GetAttribute("base-type"); if (baseClass.Length > 0) { // If a base type is specified, use the wrapper of that base type TypedClassDescriptor parent = Registry.LookupClassByName(baseClass) as TypedClassDescriptor; if (parent != null) { wrapper = parent.WrapperType; } } else { for (Type type = wrapped.BaseType; type != null; type = type.BaseType) { TypedClassDescriptor parent = Registry.LookupClassByName(type.FullName) as TypedClassDescriptor; if (parent != null) { wrapper = parent.WrapperType; break; } } } if (wrapper == null) { throw new ArgumentException(string.Format("No wrapper type for class {0}", wrapped.FullName)); } } gtype = (GLib.GType)wrapped; cname = gtype.ToString(); string iconname = elem.GetAttribute("icon"); if (iconname.Length > 0) { try { // Using the pixbuf resource constructor generates a gdk warning. Gdk.PixbufLoader loader = new Gdk.PixbufLoader(assembly, iconname); icon = loader.Pixbuf; } catch { Console.WriteLine("Could not load icon: " + iconname); icon = GetDefaultIcon(); } } else { icon = GetDefaultIcon(); } BindingFlags flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly; // If the wrapper is inherited from a base class, ignore the CreateInstance method // since it is going to create an instance of the base class. if (!inheritedWrapper) { ctorMethodInfoWithClass = wrapper.GetMethod("CreateInstance", flags, null, new Type[] { typeof(ClassDescriptor) }, null); if (ctorMethodInfoWithClass == null) { ctorMethodInfo = wrapper.GetMethod("CreateInstance", flags, null, Type.EmptyTypes, null); } } // Look for a constructor even if a CreateInstance method was // found, since it may return null. cinfo = wrapped.GetConstructor(Type.EmptyTypes); if (cinfo == null) { useGTypeCtor = true; cinfo = wrapped.GetConstructor(new Type[] { typeof(IntPtr) }); } Load(elem); }
public TypedClassDescriptor (Assembly assembly, XmlElement elem) { bool inheritedWrapper = false; wrapped = Registry.GetType (elem.GetAttribute ("type"), true); if (elem.HasAttribute ("wrapper")) wrapper = Registry.GetType (elem.GetAttribute ("wrapper"), true); else { inheritedWrapper = true; string baseClass = elem.GetAttribute ("base-type"); if (baseClass.Length > 0) { // If a base type is specified, use the wrapper of that base type TypedClassDescriptor parent = Registry.LookupClassByName (baseClass) as TypedClassDescriptor; if (parent != null) wrapper = parent.WrapperType; } else { for (Type type = wrapped.BaseType; type != null; type = type.BaseType) { TypedClassDescriptor parent = Registry.LookupClassByName (type.FullName) as TypedClassDescriptor; if (parent != null) { wrapper = parent.WrapperType; break; } } } if (wrapper == null) throw new ArgumentException (string.Format ("No wrapper type for class {0}", wrapped.FullName)); } gtype = (GLib.GType)wrapped; cname = gtype.ToString (); string iconname = elem.GetAttribute ("icon"); if (iconname.Length > 0) { try { // Using the pixbuf resource constructor generates a gdk warning. Gdk.PixbufLoader loader = new Gdk.PixbufLoader (assembly, iconname); icon = loader.Pixbuf; } catch { Console.WriteLine ("Could not load icon: " + iconname); icon = GetDefaultIcon (); } } else icon = GetDefaultIcon (); BindingFlags flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly; // If the wrapper is inherited from a base class, ignore the CreateInstance method // since it is going to create an instance of the base class. if (!inheritedWrapper) { ctorMethodInfoWithClass = wrapper.GetMethod ("CreateInstance", flags, null, new Type[] { typeof(ClassDescriptor)}, null); if (ctorMethodInfoWithClass == null) { ctorMethodInfo = wrapper.GetMethod ("CreateInstance", flags, null, Type.EmptyTypes, null); } } // Look for a constructor even if a CreateInstance method was // found, since it may return null. cinfo = wrapped.GetConstructor (Type.EmptyTypes); if (cinfo == null) { useGTypeCtor = true; cinfo = wrapped.GetConstructor (new Type[] { typeof (IntPtr) }); } Load (elem); }