本文整理汇总了C#中IVsProject.GetItemContext方法的典型用法代码示例。如果您正苦于以下问题:C# IVsProject.GetItemContext方法的具体用法?C# IVsProject.GetItemContext怎么用?C# IVsProject.GetItemContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IVsProject
的用法示例。
在下文中一共展示了IVsProject.GetItemContext方法的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: getFSharpProjectNode
/// <summary>
/// Retrieves the FSharp project node from the IVsProject interface
/// </summary>
/// <param name="root"></param>
/// <returns></returns>
public static Microsoft.VisualStudio.FSharp.ProjectSystem.ProjectNode getFSharpProjectNode(IVsProject root)
{
IOLEServiceProvider sp;
ErrorHandler.ThrowOnFailure(root.GetItemContext(VSConstants.VSITEMID_ROOT, out sp));
IntPtr objPtr = IntPtr.Zero;
try
{
Guid hierGuid = typeof(VSLangProj.VSProject).GUID;
Guid UNKguid = NativeMethods.IID_IUnknown;
ErrorHandler.ThrowOnFailure(sp.QueryService(ref hierGuid, ref UNKguid, out objPtr));
var OAVSProject = (VSLangProj.VSProject)Marshal.GetObjectForIUnknown(objPtr);
var OAProject = (Microsoft.VisualStudio.FSharp.ProjectSystem.Automation.OAProject)OAVSProject.Project;
return OAProject.Project;
}
finally
{
if (objPtr != IntPtr.Zero)
Marshal.Release(objPtr);
}
}