/// <summary> /// Returns the list of available types. /// </summary> /// <param name="baseType">The base type to match. Can be null.</param> /// <param name="excludeGlobalTypes">Determines whether types /// from all referenced assemblies should be checked.</param> public ICollection GetTypes(Type baseType, bool excludeGlobalTypes) { List <Type> types = new List <Type>(); if (baseType == null) { baseType = typeof(object); } LoggingService.Debug("TypeDiscoveryService.GetTypes for " + baseType.FullName + "excludeGlobalTypes=" + excludeGlobalTypes.ToString()); //seek in all assemblies //allow to work designers like columns editor in datagridview // Searching types can cause additional assemblies to be loaded, so we need to use // ToArray to prevent an exception if the collection changes. foreach (Assembly asm in TypeResolutionService.DesignerAssemblies.ToArray()) { if (excludeGlobalTypes) { if (GacInterop.IsWithinGac(asm.Location)) { continue; } } AddDerivedTypes(baseType, asm, types); } LoggingService.Debug("TypeDiscoveryService returns " + types.Count + " types"); // TODO - Don't look in all assemblies. // Should use the current project and its referenced assemblies // as well as System.Windows.Forms. return(types); }
/// <summary> /// Loads the assembly represented by the project content. Returns null on failure. /// </summary> public Assembly LoadAssembly(IProjectContent pc) { // prevent StackOverflow when project contents have cyclic dependencies // Very popular example of cyclic dependency: System <-> System.Xml (yes, really!) if (projectContentsCurrentlyLoadingAssembly.ContainsKey(pc)) { return(null); } projectContentsCurrentlyLoadingAssembly.Add(pc, null); try { // load dependencies of current assembly foreach (IProjectContent rpc in pc.ReferencedContents) { if (rpc is ParseProjectContent) { LoadAssembly(rpc); } else if (rpc is ReflectionProjectContent) { ReflectionProjectContent rrpc = (ReflectionProjectContent)rpc; if (rrpc.AssemblyFullName != typeof(object).FullName && !GacInterop.IsWithinGac(rrpc.AssemblyLocation)) { LoadAssembly(rpc); } } } } finally { projectContentsCurrentlyLoadingAssembly.Remove(pc); } if (pc.Project != null) { return(LoadAssembly(((IProject)pc.Project).OutputAssemblyFullPath)); } else if (pc is ReflectionProjectContent) { ReflectionProjectContent rpc = (ReflectionProjectContent)pc; if (GacInterop.IsWithinGac(rpc.AssemblyLocation)) { return(LoadAssembly(new AssemblyName(rpc.AssemblyFullName), false)); } else { return(LoadAssembly(rpc.AssemblyLocation)); } } else { return(null); } }
void ScanProjectAssemblies() { // custom user controls don't need custom images loadImages = false; foreach (IProjectContent pc in AllProjectContentsWithReferences) { if (pc.Project == null) { ReflectionProjectContent rpc = pc as ReflectionProjectContent; if (rpc == null) { continue; } if (rpc.AssemblyFullName == typeof(object).Assembly.FullName) { continue; } if (GacInterop.IsWithinGac(rpc.AssemblyLocation)) { continue; } } foreach (IClass c in pc.Classes) { var ctors = c.Methods.Where(method => method.IsConstructor); if (ctors.Any() && !ctors.Any( (IMethod method) => method.IsPublic && method.Parameters.Count == 0 )) { // do not include classes that don't have a public parameterless constructor continue; } foreach (IClass subClass in c.ClassInheritanceTree) { if (subClass.FullyQualifiedName == "System.Windows.Forms.Form") { break; // is not a design component } if (subClass.FullyQualifiedName == "System.ComponentModel.IComponent") { goto isDesignComponent; } foreach (IAttribute attr in subClass.Attributes) { if (attr.AttributeType.FullyQualifiedName == "System.ComponentModel.DesignTimeVisibleAttribute") { if (attr.PositionalArguments.Count == 1 && attr.PositionalArguments[0] is bool) { if ((bool)attr.PositionalArguments[0]) { goto isDesignComponent; } } else { goto isDesignComponent; } } } } // is not a design component continue; isDesignComponent: this.Items.Add(new SideTabItemDesigner(c.Name, new CustomComponentToolBoxItem(c))); } } }