IFileRenameProvider --> IProjectFile Follow
Hi, as part of simplifying my plugin I'd like to be able to convert IDeclaredElement to IProjectFile from within IFileRenameProvider.GetFileRenames Can you give me any pointers as to how to identify IProjectFile? Is the only way to search all projects for the declared element? public IEnumerable
GetFileRenames(IDeclaredElement declaredElement, string newName)Please sign in to leave a comment.
It really depends on what the declared element is pointing to. It might be pointing to an variable, class, decompiled type, path, even a colour! If you're after the file that contains a declaration, you should be able to get the declarations of the element, and for each declaration work backwards to get the IFile, the IPsiSourceFile and then the IProjectFile. There should be various extension methods that return these things.
var typeElement = declaredElement as ITypeElement; if (typeElement == null) return; typeElement.GetSourceFiles().First().ToProjectFile()