예제 #1
0
파일: Object.cs 프로젝트: mhutch/gtk-sharp
        static void AddInterfaces(GType gtype, Type t, ref bool handlers_overridden)
        {
            foreach (Type iface in t.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;
                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;
                }

                if (!iface.IsAssignableFrom(t.BaseType))
                {
                    GInterfaceInfo info = adapter.Info;
                    info.Data = gtype.GetClassPtr();
                    //FIXME:  overiding prop is done inside the init of interface adapter
                    // not sure that it is the good solution but
                    // it is the only one I found without exception or loop
                    g_type_add_interface_static(gtype.Val, adapter.GType.Val, ref info);
                }
                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 = t.GetProperty(p.Name, BindingFlags.Public | BindingFlags.Instance);
                    if (declared_prop == null)
                    {
                        continue;
                    }
                    IntPtr param_spec = FindInterfaceProperty(adapter.GType, property_attr.Name);

                    Dictionary <IntPtr, PropertyInfo> props;
                    if (!Properties.TryGetValue(t, out props))
                    {
                        props          = new Dictionary <IntPtr, PropertyInfo> ();
                        Properties [t] = props;
                    }
                    props [param_spec] = declared_prop;
                }
            }
        }
예제 #2
0
        static void AddInterfaces(GType gtype, Type t)
        {
            foreach (Type iface in t.GetInterfaces())
            {
                if (!iface.IsDefined(typeof(GInterfaceAttribute), true) || iface.IsAssignableFrom(t.BaseType))
                {
                    continue;
                }

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

                GInterfaceInfo info = adapter.Info;
                g_type_add_interface_static(gtype.Val, adapter.GType.Val, ref info);
            }
        }
예제 #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);
                        }
                    }
                }
            }
예제 #4
0
            private void AddGInterfaces()
            {
                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;

                    if (!iface.IsAssignableFrom(Type.BaseType))
                    {
                        GInterfaceInfo info = adapter.Info;
                        info.Data = gtype.Val;
                        g_type_add_interface_static(gtype.Val, adapter.GInterfaceGType.Val, ref info);
                        adapters.Add(adapter);
                    }
                }
            }
예제 #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;
                    }
                }
            }
예제 #6
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);
                        }
                    }
                }
            }