当前位置: 首页>>代码示例>>C#>>正文


C# IVsHierarchy.ParseCanonicalName方法代码示例

本文整理汇总了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";
        }
开发者ID:zbrad,项目名称:oncheckin-transformer,代码行数:18,代码来源:OnCheckinTransforms.VisualStudioPackage.cs

示例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;
        }
开发者ID:icool123,项目名称:T4Toolbox,代码行数:30,代码来源:TemplatedFileGenerator.cs

示例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;
        }
开发者ID:PDarkTemplar,项目名称:UnityRefactorHelper,代码行数:62,代码来源:ProjectService.cs


注:本文中的IVsHierarchy.ParseCanonicalName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。