本文整理汇总了C#中IVsHierarchy.ParseCanonicalName方法的典型用法代码示例。如果您正苦于以下问题:C# IVsHierarchy.ParseCanonicalName方法的具体用法?C# IVsHierarchy.ParseCanonicalName怎么用?C# IVsHierarchy.ParseCanonicalName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IVsHierarchy
的用法示例。
在下文中一共展示了IVsHierarchy.ParseCanonicalName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddTransformToSolution
private void AddTransformToSolution(ProjectItem selectedProjectItem, string itemName, string projectPath, IVsHierarchy heirarchy)
{
string itemPath = Path.Combine(projectPath, itemName);
if (!File.Exists(itemPath)) return;
uint removeFileId;
heirarchy.ParseCanonicalName(itemPath, out removeFileId);
if (removeFileId < uint.MaxValue)
{
var itemToRemove = GetProjectItemFromHierarchy(heirarchy, removeFileId);
if (itemToRemove!=null) itemToRemove.Remove();
}
// and add it to the project
var addedItem = selectedProjectItem.ProjectItems.AddFromFile(itemPath);
// we need to set the Build Action to None to ensure that it doesn't get published for web projects
addedItem.Properties.Item("ItemType").Value = "None";
}
示例2: ResolveFromLastGenOutputMetadata
private string ResolveFromLastGenOutputMetadata(IVsHierarchy hierarchy, uint inputFileId, string inputFileName)
{
var propertyStorage = (IVsBuildPropertyStorage)hierarchy;
string lastGenOutputFileName;
if (ErrorHandler.Succeeded(propertyStorage.GetItemAttribute(inputFileId, ItemMetadata.LastGenOutput, out lastGenOutputFileName)) &&
string.Equals(".tt", Path.GetExtension(lastGenOutputFileName), StringComparison.OrdinalIgnoreCase))
{
// Remove the script file from the project to prevent Visual Studio from deleting it
string inputDirectory = Path.GetDirectoryName(inputFileName);
string lastGenOutputFilePath = Path.Combine(inputDirectory, lastGenOutputFileName);
string tempFilePath = Path.Combine(inputDirectory, Path.GetRandomFileName());
File.Move(lastGenOutputFilePath, tempFilePath);
uint lastGenOutputFileId;
ErrorHandler.ThrowOnFailure(hierarchy.ParseCanonicalName(lastGenOutputFilePath, out lastGenOutputFileId));
int result;
var project = (IVsProject2)hierarchy;
ErrorHandler.ThrowOnFailure(project.RemoveItem(default(uint), lastGenOutputFileId, out result));
File.Move(tempFilePath, lastGenOutputFilePath);
// Save name of the script file in the <Template> metadata item of the project item and refresh the Properties window
ErrorHandler.ThrowOnFailure(propertyStorage.SetItemAttribute(inputFileId, ItemMetadata.Template, lastGenOutputFileName));
var propertyBrowser = (IVSMDPropertyBrowser)this.GlobalServiceProvider.GetService(typeof(SVSMDPropertyBrowser));
propertyBrowser.Refresh();
return lastGenOutputFileName;
}
return null;
}
示例3: ExamineProjectItem
private static string ExamineProjectItem(ProjectItem item, ProjectScanItem projectScan,
IVsHierarchy projectHierarchy)
{
var fileName = item.FileNames[1];
if (Path.GetExtension(fileName) != ".cs") return null;
var code = item.FileCodeModel;
if (code == null) return null;
var className = string.Empty;
var namespaceName = string.Empty;
foreach (CodeElement codeElement in code.CodeElements)
{
if (string.IsNullOrEmpty(className))
className = ExamineCodeElement(codeElement, vsCMElement.vsCMElementClass);
if (string.IsNullOrEmpty(namespaceName))
namespaceName = ExamineCodeElement(codeElement, vsCMElement.vsCMElementNamespace);
if (!string.IsNullOrEmpty(className) && !string.IsNullOrEmpty(namespaceName))
break;
}
if (string.IsNullOrEmpty(className)) return null;
uint itemId;
if (projectHierarchy.ParseCanonicalName(item.FileNames[0], out itemId) == VSConstants.S_OK)
{
var buildPropertyStorage =
projectHierarchy as IVsBuildPropertyStorage;
if (buildPropertyStorage == null) return null;
string fileGuid;
buildPropertyStorage.GetItemAttribute(itemId, PersistentFileGuidName, out fileGuid);
if (string.IsNullOrEmpty(fileGuid))
{
fileGuid = Guid.NewGuid().ToString();
buildPropertyStorage.SetItemAttribute(itemId, PersistentFileGuidName, fileGuid);
item.ContainingProject.Save();
}
if (string.IsNullOrEmpty(fileGuid)) return null;
var file = projectScan.Files.FirstOrDefault(x => x.ProjectFileId == fileGuid);
var fileId = FileIdGenerator.Compute(namespaceName, className);
if (file == null)
{
projectScan.Files.Add(new FileScanItem { ProjectFileId = fileGuid, OldId = fileId });
}
else
{
var newId = fileId;
if (file.OldId != newId)
file.NewId = newId;
}
return fileGuid;
}
return null;
}