public IAssemblyModel GetAssemblyModel(FileName fileName, bool includeInternalMembers = false) { LoadedAssembly assembly = GetLoadedAssembly(fileName, includeInternalMembers); if (assembly.Model == null) { // Get references DefaultAssemblySearcher assemblySearcher = new DefaultAssemblySearcher(fileName); var referencedAssemblies = new List <IUnresolvedAssembly>(); foreach (var referencedAssemblyName in assembly.References) { var assemblyFileName = assemblySearcher.FindAssembly(referencedAssemblyName); if (assemblyFileName != null) { var loadedRefAssembly = GetLoadedAssembly(assemblyFileName, includeInternalMembers); if (loadedRefAssembly != null) { referencedAssemblies.Add(loadedRefAssembly.ProjectContent); } } } IEntityModelContext context = new AssemblyEntityModelContext(assembly.ProjectContent, referencedAssemblies.ToArray()); IUpdateableAssemblyModel model = SD.GetService <IModelFactory>().CreateAssemblyModel(context); model.Update(EmptyList <IUnresolvedTypeDefinition> .Instance, assembly.ProjectContent.TopLevelTypeDefinitions.ToList()); model.AssemblyName = assembly.ProjectContent.AssemblyName; model.FullAssemblyName = assembly.ProjectContent.FullAssemblyName; model.UpdateReferences(assembly.References); assembly.Model = model; } return(assembly.Model); }
void UpdateReferences() { references.Clear(); var assemblyParserService = SD.GetRequiredService<IAssemblyParserService>(); if (assemblyModel.References != null) { foreach (var referencedAssemblyName in assemblyModel.References) { DefaultAssemblySearcher searcher = new DefaultAssemblySearcher(assemblyModel.Location); var resolvedFile = searcher.FindAssembly(referencedAssemblyName); var referenceAssemblyModel = assemblyParserService.GetAssemblyModel(resolvedFile); references.Add(referenceAssemblyModel); } } }
public IAssemblyModel GetAssemblyModel(FileName fileName, bool includeInternalMembers = false) { LoadedAssembly assembly = GetLoadedAssembly(fileName, includeInternalMembers); if (assembly.Model == null) { // Get references DefaultAssemblySearcher assemblySearcher = new DefaultAssemblySearcher(fileName); var referencedAssemblies = new List<IUnresolvedAssembly>(); foreach (var referencedAssemblyName in assembly.References) { var assemblyFileName = assemblySearcher.FindAssembly(referencedAssemblyName); if (assemblyFileName != null) { var loadedRefAssembly = GetLoadedAssembly(assemblyFileName, includeInternalMembers); if (loadedRefAssembly != null) { referencedAssemblies.Add(loadedRefAssembly.ProjectContent); } } } IEntityModelContext context = new AssemblyEntityModelContext(assembly.ProjectContent, referencedAssemblies.ToArray()); IUpdateableAssemblyModel model = SD.GetService<IModelFactory>().CreateAssemblyModel(context); model.Update(EmptyList<IUnresolvedTypeDefinition>.Instance, assembly.ProjectContent.TopLevelTypeDefinitions.ToList()); model.AssemblyName = assembly.ProjectContent.AssemblyName; model.FullAssemblyName = assembly.ProjectContent.FullAssemblyName; model.UpdateReferences(assembly.References); assembly.Model = model; } return assembly.Model; }
public override void Execute(object parameter) { var classBrowser = SD.GetService<IClassBrowser>(); if (classBrowser != null) { IAssemblyModel assemblyModel = parameter as IAssemblyModel; if (assemblyModel == null) { IAssemblyReferenceModel assemblyReference = parameter as IAssemblyReferenceModel; if (assemblyReference == null) { // Neither assembly model, nor a assembly reference model return; } // Model is an assembly reference IAssemblyParserService assemblyParserService = SD.GetRequiredService<IAssemblyParserService>(); DefaultAssemblySearcher searcher = new DefaultAssemblySearcher(assemblyReference.ParentAssemblyModel.Location); var resolvedFile = searcher.FindAssembly(assemblyReference.AssemblyName); assemblyModel = assemblyParserService.GetAssemblyModelSafe(resolvedFile); } if (assemblyModel != null) { // Try to remove AssemblyModel from list of UnpinnedAssemblies classBrowser.UnpinnedAssemblies.Assemblies.RemoveAll(a => a.FullAssemblyName == assemblyModel.FullAssemblyName); if (!classBrowser.MainAssemblyList.Assemblies.Contains(assemblyModel)) classBrowser.MainAssemblyList.Assemblies.Add(assemblyModel); } } }
ITypeDefinitionModel GetTypeDefinitionModel(ITypeDefinition mainTypeDefinition, ITypeDefinition baseTypeDefinition) { ITypeDefinitionModel resolveTypeDefModel = null; var assemblyFileName = mainTypeDefinition.ParentAssembly.GetRuntimeAssemblyLocation(); IAssemblyModel assemblyModel = null; try { // Try to get AssemblyModel from project list IProjectService projectService = SD.GetRequiredService<IProjectService>(); if (projectService.CurrentSolution != null) { var projectOfAssembly = projectService.CurrentSolution.Projects.FirstOrDefault(p => p.AssemblyModel.Location == assemblyFileName); if (projectOfAssembly != null) { // We automatically have an AssemblyModel from project assemblyModel = projectOfAssembly.AssemblyModel; } } var assemblyParserService = SD.GetService<IAssemblyParserService>(); if (assemblyModel == null) { if (assemblyParserService != null) { if (assemblyFileName != null) { assemblyModel = assemblyParserService.GetAssemblyModel(assemblyFileName); } } } if (assemblyModel != null) { // Nothing in projects, load from assembly file resolveTypeDefModel = assemblyModel.TopLevelTypeDefinitions[baseTypeDefinition.FullTypeName]; if (resolveTypeDefModel != null) { return resolveTypeDefModel; } // Look at referenced assemblies if ((assemblyModel.References != null) && (assemblyParserService != null)) { foreach (var referencedAssemblyName in assemblyModel.References) { DefaultAssemblySearcher searcher = new DefaultAssemblySearcher(assemblyModel.Location); var resolvedFile = searcher.FindAssembly(referencedAssemblyName); var referenceAssemblyModel = assemblyParserService.GetAssemblyModel(resolvedFile); resolveTypeDefModel = referenceAssemblyModel.TopLevelTypeDefinitions[baseTypeDefinition.FullTypeName]; if (resolveTypeDefModel != null) { return resolveTypeDefModel; } } } } } catch (Exception) { // TODO Can't load the type, what to do? } return resolveTypeDefModel; }