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; } } }
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); } }
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); } } }
static extern void g_type_add_interface_static(IntPtr gtype, IntPtr iface_type, ref GInterfaceInfo info);