ダニエル --
エディターからプロジェクトへの移行は、複数のステップからなるプロセスです。まず、エディターでファイルのファイル名を取得し、そこから含まれているプロジェクトを見つけることができます。
IWPFTextView があると仮定すると、次のようなファイル名を取得できます。
public static string GetFilePath(Microsoft.VisualStudio.Text.Editor.IWpfTextView wpfTextView)
{
Microsoft.VisualStudio.Text.ITextDocument document;
if ((wpfTextView == null) ||
(!wpfTextView.TextDataModel.DocumentBuffer.Properties.TryGetProperty(typeof(Microsoft.VisualStudio.Text.ITextDocument), out document)))
return String.Empty;
// If we have no document, just ignore it.
if ((document == null) || (document.TextBuffer == null))
return String.Empty;
return document.FilePath;
}
ファイル名を取得したら、次のように親プロジェクトを取得できます。
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Interop;
public static Project GetContainingProject(string fileName)
{
if (!String.IsNullOrEmpty(fileName))
{
var dte2 = (DTE2)Package.GetGlobalService(typeof(SDTE));
if (dte2 != null)
{
var prjItem = dte2.Solution.FindProjectItem(fileName);
if (prjItem != null)
return prjItem.ContainingProject;
}
}
return null;
}
プロジェクトからコードモデルにアクセスできます。参照はあると思いますが、まだその必要はありません。
お役に立てれば...
〜キャメロン