Esempio n. 1
0
        static void AddProperties(GType gtype, System.Type t, bool register_instance_prop, ref bool handlers_overridden)
        {
            if (register_instance_prop)
            {
                IntPtr    declaring_class = gtype.GetClassPtr();
                ParamSpec pspec           = new ParamSpec("gtk-sharp-managed-instance", "", "", GType.Pointer, ParamFlags.Writable | ParamFlags.ConstructOnly);
                g_object_class_install_property(declaring_class, idx, pspec.Handle);
                idx++;
            }

            foreach (PropertyInfo pinfo in t.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly))
            {
                foreach (object attr in pinfo.GetCustomAttributes(typeof(PropertyAttribute), false))
                {
                    if (pinfo.GetIndexParameters().Length > 0)
                    {
                        throw(new InvalidOperationException(String.Format("GLib.RegisterPropertyAttribute cannot be applied to property {0} of type {1} because the property expects one or more indexed parameters", pinfo.Name, t.FullName)));
                    }

                    if (!handlers_overridden)
                    {
                        IntPtr       class_ptr     = gtype.GetClassPtr();
                        GObjectClass gobject_class = (GObjectClass)Marshal.PtrToStructure(class_ptr, typeof(GObjectClass));
                        gobject_class.get_prop_cb = GetPropertyHandler;
                        gobject_class.set_prop_cb = SetPropertyHandler;
                        Marshal.StructureToPtr(gobject_class, class_ptr, false);
                        handlers_overridden = true;
                    }
                    PropertyAttribute property_attr = attr as PropertyAttribute;
                    try {
                        IntPtr param_spec = RegisterProperty(gtype, property_attr.Name, property_attr.Nickname, property_attr.Blurb, idx, (GType)pinfo.PropertyType, pinfo.CanRead, pinfo.CanWrite);
                        Type   type       = (Type)gtype;
                        Dictionary <IntPtr, PropertyInfo> gtype_properties;
                        if (!Properties.TryGetValue(type, out gtype_properties))
                        {
                            gtype_properties  = new Dictionary <IntPtr, PropertyInfo> ();
                            Properties [type] = gtype_properties;
                        }
                        gtype_properties.Add(param_spec, pinfo);
                        idx++;
                    } catch (ArgumentException) {
                        throw new InvalidOperationException(String.Format("GLib.PropertyAttribute cannot be applied to property {0} of type {1} because the return type of the property is not supported", pinfo.Name, t.FullName));
                    }
                }
            }
        }
Esempio n. 2
0
        static void AddProperties(GType gtype, System.Type t)
        {
            uint idx = 1;

            bool handlers_overridden = false;

            foreach (PropertyInfo pinfo in t.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly))
            {
                foreach (object attr in pinfo.GetCustomAttributes(typeof(PropertyAttribute), false))
                {
                    if (pinfo.GetIndexParameters().Length > 0)
                    {
                        throw(new InvalidOperationException(String.Format("GLib.RegisterPropertyAttribute cannot be applied to property {0} of type {1} because the property expects one or more indexed parameters", pinfo.Name, t.FullName)));
                    }

                    PropertyAttribute property_attr = attr as PropertyAttribute;
                    if (!handlers_overridden)
                    {
                        gtksharp_override_property_handlers(gtype.Val, GetPropertyHandler, SetPropertyHandler);
                        handlers_overridden = true;
                    }

                    IntPtr native_name  = GLib.Marshaller.StringToPtrGStrdup(property_attr.Name);
                    IntPtr native_nick  = GLib.Marshaller.StringToPtrGStrdup(property_attr.Nickname);
                    IntPtr native_blurb = GLib.Marshaller.StringToPtrGStrdup(property_attr.Blurb);

                    IntPtr param_spec = gtksharp_register_property(gtype.Val, native_name, native_nick, native_blurb, idx, ((GType)pinfo.PropertyType).Val, pinfo.CanRead, pinfo.CanWrite);

                    GLib.Marshaller.Free(native_name);
                    GLib.Marshaller.Free(native_nick);
                    GLib.Marshaller.Free(native_blurb);

                    if (param_spec == IntPtr.Zero)
                    {
                        // The GType of the property is not supported
                        throw new InvalidOperationException(String.Format("GLib.PropertyAttribute cannot be applied to property {0} of type {1} because the return type of the property is not supported", pinfo.Name, t.FullName));
                    }

                    Properties.Add(param_spec, pinfo);
                    idx++;
                }
            }
        }
Esempio n. 3
0
            private void InitializeProperties(GInterfaceAdapter adapter, IntPtr gobject_class_handle)
            {
                foreach (PropertyInfo pinfo in adapter.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly))
                {
                    foreach (object attr in pinfo.GetCustomAttributes(typeof(PropertyAttribute), false))
                    {
                        if (pinfo.GetIndexParameters().Length > 0)
                        {
                            throw new InvalidOperationException(String.Format("Property {0} of type {1} cannot be overriden because its GLib.PropertyAttribute is expected to have one or more indexed parameters",
                                                                              pinfo.Name, adapter.GetType().FullName));
                        }

                        PropertyAttribute property_attr = attr as PropertyAttribute;
                        if (property_attr != null)
                        {
                            OverrideProperty(gobject_class_handle, property_attr.Name);
                        }
                    }
                }
            }
Esempio n. 4
0
            void AddProperties()
            {
                if (is_first_subclass)
                {
                    IntPtr    declaring_class = gtype.GetClassPtr();
                    ParamSpec pspec           = new ParamSpec("gtk-sharp-managed-instance", "", "", GType.Pointer, ParamFlags.Writable | ParamFlags.ConstructOnly);
                    g_object_class_install_property(declaring_class, idx, pspec.Handle);
                    idx++;
                }

                foreach (PropertyInfo pinfo in Type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly))
                {
                    foreach (object attr in pinfo.GetCustomAttributes(typeof(PropertyAttribute), false))
                    {
                        if (pinfo.GetIndexParameters().Length > 0)
                        {
                            throw new InvalidOperationException(String.Format("GLib.RegisterPropertyAttribute cannot be applied to property {0} of type {1} because the property expects one or more indexed parameters",
                                                                              pinfo.Name, Type.FullName));
                        }

                        OverrideHandlers(false, true);

                        PropertyAttribute property_attr = attr as PropertyAttribute;
                        try {
                            IntPtr param_spec = RegisterProperty(gtype, property_attr.Name, property_attr.Nickname, property_attr.Blurb, idx, (GType)pinfo.PropertyType, pinfo.CanRead, pinfo.CanWrite);
                            Type   type       = (Type)gtype;
                            Dictionary <IntPtr, PropertyInfo> gtype_properties;
                            if (!Properties.TryGetValue(type, out gtype_properties))
                            {
                                gtype_properties  = new Dictionary <IntPtr, PropertyInfo> ();
                                Properties [type] = gtype_properties;
                            }
                            gtype_properties.Add(param_spec, pinfo);
                            idx++;
                        } catch (ArgumentException) {
                            throw new InvalidOperationException(String.Format("GLib.PropertyAttribute cannot be applied to property {0} of type {1} because the return type of the property is not supported",
                                                                              pinfo.Name, Type.FullName));
                        }
                    }
                }
            }
Esempio n. 5
0
            void AddInterfaceProperties()
            {
                foreach (Type iface in Type.GetInterfaces())
                {
                    if (!iface.IsDefined(typeof(GInterfaceAttribute), true))
                    {
                        continue;
                    }

                    GInterfaceAttribute attr    = iface.GetCustomAttributes(typeof(GInterfaceAttribute), false) [0] as GInterfaceAttribute;
                    GInterfaceAdapter   adapter = Activator.CreateInstance(attr.AdapterType, null) as GInterfaceAdapter;

                    foreach (PropertyInfo p in iface.GetProperties())
                    {
                        PropertyAttribute[] attrs = p.GetCustomAttributes(typeof(PropertyAttribute), true) as PropertyAttribute [];
                        if (attrs.Length == 0)
                        {
                            continue;
                        }
                        PropertyAttribute property_attr = attrs [0];
                        PropertyInfo      declared_prop = Type.GetProperty(p.Name, BindingFlags.Public | BindingFlags.Instance);
                        if (declared_prop == null)
                        {
                            continue;
                        }
                        IntPtr param_spec = FindInterfaceProperty(adapter.GInterfaceGType, property_attr.Name);

                        Dictionary <IntPtr, PropertyInfo> props;
                        if (!Properties.TryGetValue(Type, out props))
                        {
                            props             = new Dictionary <IntPtr, PropertyInfo> ();
                            Properties [Type] = props;
                        }
                        props [param_spec] = declared_prop;
                    }
                }
            }