本文整理汇总了C#中IVsProject.IsDocumentInProject方法的典型用法代码示例。如果您正苦于以下问题:C# IVsProject.IsDocumentInProject方法的具体用法?C# IVsProject.IsDocumentInProject怎么用?C# IVsProject.IsDocumentInProject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IVsProject
的用法示例。
在下文中一共展示了IVsProject.IsDocumentInProject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PreGenerateCode
/// <summary>
/// Pres the content of the generate.
/// </summary>
/// <param name="vsProject">The vs project.</param>
/// <param name="inputFileName">The input file path.</param>
/// <exception cref="System.ApplicationException">
/// Unable to retrieve Visual Studio ProjectItem
/// or
/// Unable to retrieve Visual Studio ProjectItem
/// </exception>
protected void PreGenerateCode(IVsProject vsProject, string inputFileName)
{
_newFileNames.Clear();
int iFound;
uint itemId;
vsProject.IsDocumentInProject(inputFileName, out iFound, new VSDOCUMENTPRIORITY[1], out itemId);
if (iFound == 0 || itemId == 0)
throw new ApplicationException("Unable to retrieve Visual Studio ProjectItem");
IServiceProvider sp;
vsProject.GetItemContext(itemId, out sp);
if (sp == null)
throw new ApplicationException("Unable to retrieve Visual Studio ProjectItem");
var item = (new ServiceProvider(sp).GetService(typeof(ProjectItem)) as ProjectItem);
foreach (string i in this)
{
try
{
var inputFileName2 = GetFileName(i);
_newFileNames.Add(inputFileName2);
var path = Path.Combine(inputFileName.Substring(0, inputFileName.LastIndexOf(Path.DirectorySeparatorChar)), inputFileName2);
var inputFileContent2 = string.Empty;
if (File.Exists(path))
try { inputFileContent2 = File.ReadAllText(path); }
catch (Exception) { inputFileContent2 = string.Empty; }
var s = File.Create(path);
try
{
var data = GenerateChildCode(path, inputFileContent2);
s.Write(data, 0, data.Length);
s.Close();
item.ProjectItems.AddFromFile(path);
}
catch (Exception)
{
s.Close();
if (File.Exists(path))
File.Delete(path);
}
}
catch (Exception ex) { throw ex; }
}
foreach (ProjectItem childItem in item.ProjectItems)
if (!(childItem.Name.EndsWith(GetDefaultExtension()) || _newFileNames.Contains(childItem.Name)))
childItem.Delete();
}
示例2: GetProjectAndFileInfoForPath
public static bool GetProjectAndFileInfoForPath(
IVsProject vsProject, string originalPath, out IVsHierarchy projectHierarchy, out Project project, out uint fileItemId,
out bool isDocInProject) {
isDocInProject = false;
fileItemId = 0;
projectHierarchy = null;
project = null;
var priority = new VSDOCUMENTPRIORITY[1];
var isDocInProjectInt = 0;
uint foundItemId = 0;
var hr = vsProject.IsDocumentInProject(originalPath, out isDocInProjectInt, priority, out foundItemId);
if (NativeMethods.Succeeded(hr) && isDocInProjectInt == 1) {
projectHierarchy = vsProject as IVsHierarchy;
if (projectHierarchy != null) {
project = GetProject(projectHierarchy);
}
fileItemId = foundItemId;
isDocInProject = true;
}
return isDocInProject;
}