TextTemplatingReflectionProjectContent(ReflectionProjectContent projectContent) { if (projectContent != null) { AssemblyLocation = projectContent.AssemblyLocation; } }
protected override IEnumerable <IAttribute> GetAssemblyAttributes(Assembly assembly) { var pc = new ReflectionProjectContent("TestName", "testlocation", new DomAssemblyName[0], new ProjectContentRegistry()); pc.AddAssemblyAttributes(assembly); return(pc.GetAssemblyAttributes()); }
/// <summary> /// Loads the assembly represented by the project content. Returns null on failure. /// </summary> public Assembly LoadAssembly(IProjectContent pc) { WorkbenchSingleton.AssertMainThread(); // prevent StackOverflow when project contents have cyclic dependencies // Very popular example of cyclic dependency: System <-> System.Xml if (!projectContentsCurrentlyLoadingAssembly.Add(pc)) { return(null); } Assembly sdAssembly; if (IsSharpDevelopAssembly(pc, out sdAssembly)) { return(sdAssembly); } try { // load dependencies of current assembly foreach (IProjectContent rpc in pc.ThreadSafeGetReferencedContents()) { if (rpc is ParseProjectContent) { LoadAssembly(rpc); } else if (rpc is ReflectionProjectContent) { ReflectionProjectContent rrpc = (ReflectionProjectContent)rpc; if (!rrpc.IsGacAssembly) { 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 (rpc.IsGacAssembly) { return(LoadAssembly(new AssemblyName(rpc.AssemblyFullName), false)); } else { return(LoadAssembly(rpc.AssemblyLocation)); } } else { return(null); } }
protected override IClass GetClass(Type type) { ICompilationUnit cu = new ReflectionProjectContent("TestName", "testlocation", new DomAssemblyName[0], ParserService.DefaultProjectContentRegistry).AssemblyCompilationUnit; IClass c = new ReflectionClass(cu, type, type.FullName, null); cu.ProjectContent.AddClassToNamespaceList(c); return(c); }
public static string GetAssemblyLocation(ReflectionProjectContent rpc) { if (rpc == null) { throw new ArgumentNullException("rpc"); } // prefer GAC assemblies over reference assemblies: return(rpc.RealAssemblyLocation); }
protected override IClass GetClass(Type type) { ICompilationUnit cu = new ReflectionProjectContent("TestName", "testlocation", new DomAssemblyName[0], new ProjectContentRegistry()).AssemblyCompilationUnit; ((ReflectionProjectContent)cu.ProjectContent).AddReferencedContent(mscorlib); IClass c = new ReflectionClass(cu, type, type.FullName, null); cu.ProjectContent.AddClassToNamespaceList(c); return(c); }
public static void TryGoTo(AbstractEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } while ((entity is IMember) && ((IMember)entity).GenericMember is AbstractEntity) { entity = (AbstractEntity)((IMember)entity).GenericMember; } // Try to find the assembly which contains the resolved type IProjectContent pc = entity.ProjectContent; ReflectionProjectContent rpc = pc as ReflectionProjectContent; string assemblyLocation = null; if (rpc != null) { // prefer GAC assemblies over reference assemblies: assemblyLocation = FindAssemblyInNetGac(new DomAssemblyName(rpc.AssemblyFullName)); if (string.IsNullOrEmpty(assemblyLocation)) { // use file only if assembly isn't in GAC: assemblyLocation = rpc.AssemblyLocation; } } else { IProject project = pc.Project as IProject; if (project != null) { assemblyLocation = project.OutputAssemblyFullPath; } } if (string.IsNullOrEmpty(assemblyLocation)) { MessageService.ShowWarning("ILSpy AddIn: Could not determine the assembly location for " + entity.FullyQualifiedName + "."); return; } string ilspyPath = GetILSpyExeFullPathInteractive(); if (string.IsNullOrEmpty(ilspyPath)) { return; } string commandLine = "/singleInstance \"" + assemblyLocation + "\" \"/navigateTo:" + entity.DocumentationTag + "\""; LoggingService.Debug(ilspyPath + " " + commandLine); Process.Start(ilspyPath, commandLine); }
/// <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 && !FileUtility.IsBaseDirectory(GacInterop.GacRootPath, 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 (FileUtility.IsBaseDirectory(GacInterop.GacRootPath, rpc.AssemblyLocation)) { return(LoadAssembly(new AssemblyName(rpc.AssemblyFullName), false)); } else { return(LoadAssembly(rpc.AssemblyLocation)); } } else { return(null); } }
protected override IEnumerable <IAttribute> GetAssemblyAttributes(Assembly assembly) { var pc = new ReflectionProjectContent("TestName", "testlocation", new DomAssemblyName[0], new ProjectContentRegistry()); pc.AddAssemblyAttributes(assembly); MemoryStream memory = new MemoryStream(); DomPersistence.WriteProjectContent(pc, memory); memory.Position = 0; return(DomPersistence.LoadProjectContent(memory, new ProjectContentRegistry()).GetAssemblyAttributes()); }
protected override IClass GetClass(Type type) { ICompilationUnit cu = new ReflectionProjectContent("TestName", "testlocation", new DomAssemblyName[0], ParserService.DefaultProjectContentRegistry).AssemblyCompilationUnit; IClass c = new ReflectionClass(cu, type, type.FullName, null); cu.ProjectContent.AddClassToNamespaceList(c); MemoryStream memory = new MemoryStream(); DomPersistence.WriteProjectContent((ReflectionProjectContent)c.ProjectContent, memory); memory.Position = 0; return(DomPersistence.LoadProjectContent(memory, ParserService.DefaultProjectContentRegistry).Classes.Single()); }
protected override IProjectContent LoadProjectContent(string itemInclude, string itemFileName) { if (File.Exists(itemFileName)) { // we cannot reuse project contents from the default registry because they would // reference the wrong mscorlib version, causing code-completion problems // when a CF application references a CF library return(base.LoadProjectContent(itemInclude, itemFileName)); } string netPath = GetInstallFolder(); if (!string.IsNullOrEmpty(netPath) && File.Exists(Path.Combine(netPath, "mscorlib.dll"))) { string shortName = itemInclude; int pos = shortName.IndexOf(','); if (pos > 0) { shortName = shortName.Substring(0, pos); } if (File.Exists(Path.Combine(netPath, shortName + ".dll"))) { ReflectionProjectContent rpc = CecilReader.LoadAssembly(Path.Combine(netPath, shortName + ".dll"), this); if (rpc != null) { redirectedAssemblyNames.Add(shortName, rpc.AssemblyFullName); } return(rpc); } else if (File.Exists(Path.Combine(netPath, shortName))) { // perhaps shortName includes file extension ReflectionProjectContent rpc = CecilReader.LoadAssembly(Path.Combine(netPath, shortName), this); if (rpc != null) { redirectedAssemblyNames.Add(Path.GetFileNameWithoutExtension(shortName), rpc.AssemblyFullName); } return(rpc); } } else { string message = "Warning: .NET Compact Framework SDK is not installed." + Environment.NewLine; if (!TaskService.BuildMessageViewCategory.Text.Contains(message)) { TaskService.BuildMessageViewCategory.AppendText(message); } } return(base.LoadProjectContent(itemInclude, itemFileName)); }
protected override IProjectContent LoadProjectContent(string itemInclude, string itemFileName) { if (File.Exists(itemFileName)) { return(base.LoadProjectContent(itemInclude, itemFileName)); } string netPath = Path.Combine(FileUtility.NETFrameworkInstallRoot, DotnetVersion); if (File.Exists(Path.Combine(netPath, "mscorlib.dll"))) { string shortName = itemInclude; int pos = shortName.IndexOf(','); if (pos > 0) { shortName = shortName.Substring(0, pos); } if (File.Exists(Path.Combine(netPath, shortName + ".dll"))) { ReflectionProjectContent rpc = CecilReader.LoadAssembly(Path.Combine(netPath, shortName + ".dll"), this); if (rpc != null) { redirectedAssemblyNames.Add(shortName, rpc.AssemblyFullName); } return(rpc); } else if (File.Exists(Path.Combine(netPath, shortName))) { // perhaps shortName includes file extension ReflectionProjectContent rpc = CecilReader.LoadAssembly(Path.Combine(netPath, shortName), this); if (rpc != null) { redirectedAssemblyNames.Add(Path.GetFileNameWithoutExtension(shortName), rpc.AssemblyFullName); } return(rpc); } } else { string message = "Warning: Target .NET Framework version " + DotnetVersion + " is not installed." + Environment.NewLine; if (!TaskService.BuildMessageViewCategory.Text.Contains(message)) { TaskService.BuildMessageViewCategory.AppendText(message); } } return(base.LoadProjectContent(itemInclude, itemFileName)); }
protected override IClass GetClass(Type type) { ICompilationUnit cu = new ReflectionProjectContent("TestName", "testlocation", new DomAssemblyName[0], new ProjectContentRegistry()).AssemblyCompilationUnit; IClass c = new ReflectionClass(cu, type, type.FullName, null); cu.ProjectContent.AddClassToNamespaceList(c); MemoryStream memory = new MemoryStream(); DomPersistence.WriteProjectContent((ReflectionProjectContent)c.ProjectContent, memory); memory.Position = 0; ReflectionProjectContent loadedPC = DomPersistence.LoadProjectContent(memory, new ProjectContentRegistry()); loadedPC.AddReferencedContent(mscorlib); return(loadedPC.Classes.Single()); }
public void ReflectionParserTest() { ICompilationUnit cu = new ReflectionProjectContent("TestName", "testlocation", new AssemblyName[0], ParserService.DefaultProjectContentRegistry).AssemblyCompilationUnit; IClass c = new ReflectionClass(cu, typeof(TestClass <,>), typeof(TestClass <,>).FullName, null); cu.ProjectContent.AddClassToNamespaceList(c); CheckClass(c); MemoryStream memory = new MemoryStream(); DomPersistence.WriteProjectContent((ReflectionProjectContent)cu.ProjectContent, memory); memory.Position = 0; foreach (IClass c2 in DomPersistence.LoadProjectContent(memory, ParserService.DefaultProjectContentRegistry).Classes) { CheckClass(c2); } }
public bool NavigateToEntity(IEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } // Get the underlying entity for generic instance members while ((entity is IMember) && ((IMember)entity).GenericMember != null) { entity = ((IMember)entity).GenericMember; } IClass declaringType = (entity as IClass) ?? entity.DeclaringType; if (declaringType == null) { return(false); } // get the top-level type while (declaringType.DeclaringType != null) { declaringType = declaringType.DeclaringType; } ReflectionProjectContent rpc = entity.ProjectContent as ReflectionProjectContent; if (rpc != null) { string assemblyLocation = ILSpyController.GetAssemblyLocation(rpc); if (!string.IsNullOrEmpty(assemblyLocation) && File.Exists(assemblyLocation)) { NavigateTo(assemblyLocation, declaringType.DotNetName, ((AbstractEntity)entity).DocumentationTag); return(true); } } return(false); }
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 (FileUtility.IsBaseDirectory(GacInterop.GacRootPath, 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))); } } }
public override void Run() { IClass c; IMember m; MemberNode mn = this.Owner as MemberNode; if (mn != null) { m = mn.Member; c = m.DeclaringType; } else { ClassNode cn = this.Owner as ClassNode; if (cn != null) { c = cn.Class; m = null; } else { ClassMemberBookmark cmbm = this.Owner as ClassMemberBookmark; if (cmbm != null) { m = cmbm.Member; c = m.DeclaringType; } else { ClassBookmark cbm = this.Owner as ClassBookmark; if (cbm != null) { c = cbm.Class; m = null; } else { MessageService.ShowWarning("Reflector AddIn: Could not determine the class for the selected element. Owner: " + ((this.Owner == null) ? "<null>" : this.Owner.ToString())); return; } } } } if (c == null) { MessageService.ShowWarning("Reflector AddIn: Could not determine the class for the selected element (known owner). Owner: " + this.Owner.ToString()); return; } // Try to find the assembly which contains the resolved type IProjectContent pc = c.ProjectContent; ReflectionProjectContent rpc = pc as ReflectionProjectContent; string assemblyLocation = null; if (rpc != null) { assemblyLocation = rpc.AssemblyLocation; } else { IProject project = pc.Project as IProject; if (project != null) { assemblyLocation = project.OutputAssemblyFullPath; } } if (String.IsNullOrEmpty(assemblyLocation)) { MessageService.ShowWarning("Reflector AddIn: Could not determine the assembly location for " + c.ToString() + "."); return; } AbstractEntity entity = m as AbstractEntity; if (entity == null) { entity = c as AbstractEntity; } if (entity != null) { LoggingService.Debug("ReflectorAddIn: Trying to go to " + entity.DocumentationTag + " in " + assemblyLocation); ReflectorController.TryGoTo(assemblyLocation, entity); } }