Beispiel #1
0
        public void AddProjectDlls(OpenedFile file)
        {
            var compilation           = SD.ParserService.GetCompilationForFile(file.FileName);
            var typeResolutionService = new TypeResolutionService(file.FileName);

            foreach (var reference in compilation.ReferencedAssemblies)
            {
                string assemblyFileName = reference.GetReferenceAssemblyLocation();

                if (assemblyFileName != null && !addedAssemblies.Contains(assemblyFileName))
                {
                    try {
                        // DO NOT USE Assembly.LoadFrom!!!
                        // see http://community.sharpdevelop.net/forums/t/19968.aspx
                        Assembly assembly = typeResolutionService.LoadAssembly(assemblyFileName);
                        if (assembly == null)
                        {
                            continue;
                        }

                        SideTab sideTab = new SideTab(sideBar, assembly.FullName.Split(new[] { ',' })[0]);
                        sideTab.DisplayName        = StringParser.Parse(sideTab.Name);
                        sideTab.CanBeDeleted       = false;
                        sideTab.ChosenItemChanged += OnChosenItemChanged;

                        sideTab.Items.Add(new WpfSideTabItem());

                        foreach (var t in assembly.GetExportedTypes())
                        {
                            if (IsControl(t))
                            {
                                sideTab.Items.Add(new WpfSideTabItem(t));
                            }
                        }

                        if (sideTab.Items.Count > 1)
                        {
                            sideBar.Tabs.Add(sideTab);
                        }

                        addedAssemblies.Add(assemblyFileName);
                    } catch (Exception ex) {
                        WpfViewContent.DllLoadErrors.Add(new SDTask(new BuildError(assemblyFileName, ex.Message)));
                    }
                }
            }
        }
 void Init(IDesignerHost host)
 {
     LoggingService.Debug("Initializing MyToolBoxItem: " + className);
     if (host == null)
     {
         throw new ArgumentNullException("host");
     }
     if (assemblyLocation != null)
     {
         TypeResolutionService typeResolutionService = host.GetService(typeof(ITypeResolutionService)) as TypeResolutionService;
         if (typeResolutionService == null)
         {
             throw new InvalidOperationException("Cannot initialize CustomComponentToolBoxItem because the designer host does not provide a SharpDevelop TypeResolutionService.");
         }
         Assembly asm = typeResolutionService.LoadAssembly(assemblyLocation);
         if (asm != null && usedAssembly != asm)
         {
             Initialize(asm.GetType(className));
             usedAssembly = asm;
         }
     }
 }