다소 큰 솔루션을 탐색하는 데 도움이되는 고유 한 Visual Studio 2010 Extension을 작성하고 있습니다.
이미 일부 확장 검색 기준에 따라 클래스 이름과 함수 이름을 표시하는 VS 확장을 기반으로하는 대화 상자가 있습니다. 이제이 클래스/메서드를 클릭하면 올바른 파일을 열고 함수로 바로 이동할 수 있습니다.
지금 내가하고 싶은 것은 그 기능의 시작 부분에 커서를 놓는 것입니다. 함수에 뛰어
내 코드는 다음과 같습니다 여기Visual Studio Extension으로 커서 위치 설정
Solution currentSolution = ((EnvDTE.DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.10.0")).Solution;
ProjectItem requestedItem = GetRequestedProjectItemToOpen(currentSolution.Projects, "fileToBeOpened");
if (requestedItem != null)
{
// open the document
Window window = requestedItem.Open(Constants.vsViewKindCode);
window.Activate();
// search for the function to be opened
foreach (CodeElement codeElement in requestedItem.FileCodeModel.CodeElements)
{
// get the namespace elements
if (codeElement.Kind == vsCMElement.vsCMElementNamespace)
{
foreach (CodeElement namespaceElement in codeElement.Children)
{
// get the class elements
if (namespaceElement.Kind == vsCMElement.vsCMElementClass)
{
foreach (CodeElement classElement in namespaceElement.Children)
{
try
{
// get the function elements
if (classElement.Kind == vsCMElement.vsCMElementFunction)
{
if (classElement.Name.Equals("functionToBeOpened", StringComparison.Ordinal))
{
classElement.StartPoint.TryToShow(vsPaneShowHow.vsPaneShowTop, null);
this.Close();
}
}
}
catch
{
}
}
}
}
}
}
}
중요한 점은 올바른 파일을 열 수 및 classElement.StartPoint.TryToShow(vsPaneShowHow.vsPaneShowTop, null);
올바른 기능으로 이동합니다 window.Activate();
이다.
커서는 요청 된 기능의 시작으로 설정되지 않습니다. 어떻게해야합니까? 나는 classElement.StartPoint.SetCursor()
과 같은 것을 생각하고있다.
건배 사이먼
Cyclomatically 단지? 또한, 당신이 당신이 찾고있는 것을 발견 할 때 당신이 그 방법에서 벗어나지 않고, 어떤 부작용 (WAG)을 가지고있는 것처럼 보입니다. – Will
@ 윌 : 예, 알고 있습니다. 이것은 프로토 타입 코드의 일종입니다. 요청한 클래스와 함수를 어떻게 여는 지 보여주기 위해 ... –