예제 #1
0
        void AddObjects(XmlDocument doc, AssemblyResolver resolver, string basePath, AssemblyDefinition adef)
        {
            Dictionary <TypeDefinition, ToolboxItemInfo> localObjects = new Dictionary <TypeDefinition, ToolboxItemInfo> ();

            foreach (TypeDefinition tdef in adef.MainModule.Types)
            {
                AddObject(tdef, localObjects, resolver, basePath, adef);
            }

            foreach (KeyValuePair <TypeDefinition, ToolboxItemInfo> item in localObjects)
            {
                TypeDefinition  tdef   = item.Key;
                ToolboxItemInfo tbinfo = item.Value;
                XmlElement      elem   = doc.CreateElement("object");
                elem.SetAttribute("type", tdef.FullName);
                elem.SetAttribute("allow-children", "false");
                elem.SetAttribute("palette-category", tbinfo.PaletteCategory);
                if (tdef.IsNotPublic)
                {
                    elem.SetAttribute("internal", "true");
                }
                doc.DocumentElement.AppendChild(elem);

                TypeDefinition curDef = tdef;
                while (curDef != null && curDef.FullName != tbinfo.BaseType)
                {
                    if (curDef != tdef && localObjects.ContainsKey(curDef))
                    {
                        tbinfo.BaseType = curDef.FullName;
                        break;
                    }
                    else if (curDef.Module.Assembly.Name.Name == "gtk-sharp")
                    {
                        tbinfo.BaseType = curDef.FullName;
                        break;
                    }
                    else if (curDef != tdef && GetToolboxItemInfo(resolver, basePath, curDef.Module.Assembly, curDef, false) != null)
                    {
                        tbinfo.BaseType = curDef.FullName;
                        break;
                    }
                    if (curDef.Module.Assembly != adef)
                    {
                        LibraryInfo li = Refresh(resolver, curDef.Module.FullyQualifiedName, basePath);
                        if (li.HasWidgets && li.GetToolboxItem(curDef.FullName, curDef.Module.Assembly.Name.Name) != null)
                        {
                            tbinfo.BaseType = curDef.FullName;
                            break;
                        }
                    }
                    AddProperties(curDef, elem);
                    AddEvents(curDef, elem);
                    if (curDef.BaseType != null && curDef.BaseType.FullName != tbinfo.BaseType)
                    {
                        curDef = FindTypeDefinition(resolver, adef, basePath, curDef.BaseType.FullName);
                    }
                    else
                    {
                        curDef = null;
                    }
                }

                elem.SetAttribute("base-type", tbinfo.BaseType);
            }
        }
예제 #2
0
        ToolboxItemInfo GetToolboxItemInfo(AssemblyResolver resolver, string baseDirectory, AssemblyDefinition asm, TypeDefinition tdef, bool checkBaseType)
        {
            if (tdef == null)
            {
                return(null);
            }

            ToolboxItemInfo info     = null;
            string          category = "General";

            foreach (CustomAttribute attr in tdef.CustomAttributes)
            {
                switch (attr.AttributeType.FullName)
                {
                case "System.ComponentModel.ToolboxItemAttribute":
                    if (attr.ConstructorArguments.Count > 0)
                    {
                        object param = attr.ConstructorArguments [0].Value;
                        if (param == null)
                        {
                            return(null);
                        }
                        else if (param.GetType() == typeof(bool))
                        {
                            if ((bool)param)
                            {
                                info = new ToolboxItemInfo("Gtk.Widget");
                            }
                            else
                            {
                                return(null);
                            }
                        }
                        else if (param.GetType() == typeof(TypeReference))
                        {
                            info = new ToolboxItemInfo("Gtk.Widget");
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    break;

                case "System.ComponentModel.CategoryAttribute":
                    if (attr.ConstructorArguments.Count > 0)
                    {
                        object param = attr.ConstructorArguments [0].Value;
                        if (param.GetType() == typeof(string))
                        {
                            category = (string)param;
                        }
                    }
                    break;

                default:
                    continue;
                }
            }

            if (info == null && checkBaseType && tdef.BaseType != null)
            {
                string baseName = tdef.BaseType.FullName;

                foreach (AssemblyNameReference aref in asm.MainModule.AssemblyReferences)
                {
                    LibraryInfo libInfo = GetInfo(resolver, aref.FullName, baseDirectory);
                    if (libInfo != null && libInfo.HasWidgets)
                    {
                        ToolboxItemInfo binfo = libInfo.GetToolboxItem(baseName, aref.Name);
                        if (binfo != null)
                        {
                            info     = new ToolboxItemInfo(baseName);
                            category = binfo.PaletteCategory;
                            break;
                        }
                    }
                }
            }

            if (info != null)
            {
                info.PaletteCategory = category;
            }

            return(info);
        }