Datei: NDOPackage/ProjectExtensions.cs
Last Commit (946ad0e)
| 1 | using System; |
| 2 | using System. Collections. Generic; |
| 3 | using System.Linq; |
| 4 | using System.Text; |
| 5 | using System.Threading.Tasks; |
| 6 | using Community.VisualStudio.Toolkit; |
| 7 | using Microsoft.VisualStudio.Shell.Interop; |
| 8 | |
| 9 | namespace NDOVsPackage |
| 10 | { |
| 11 | ····internal static class ProjectExtensions |
| 12 | ····{ |
| 13 | ········public static EnvDTE.Project DteProject( this Project project ) |
| 14 | ········{ |
| 15 | ············ThreadHelper.ThrowIfNotOnUIThread(); |
| 16 | |
| 17 | ············var projects = ApplicationObject.VisualStudioApplication.Solution.Projects; |
| 18 | ············EnvDTE.Project dteProj = null; |
| 19 | ············foreach (EnvDTE.Project proj in projects) |
| 20 | ············{ |
| 21 | ················if (proj.Name == project.Name) |
| 22 | ················{ |
| 23 | ····················dteProj = proj; |
| 24 | ····················break; |
| 25 | ················} |
| 26 | ············} |
| 27 | |
| 28 | ············return dteProj; |
| 29 | ········} |
| 30 | |
| 31 | ········public static IVsHierarchy GetVsHierarchy( this EnvDTE.Project project ) |
| 32 | ········{ |
| 33 | ············ThreadHelper.ThrowIfNotOnUIThread(); |
| 34 | ············IVsHierarchy projectHierarchy = null; |
| 35 | |
| 36 | ············( (IVsSolution) Package.GetGlobalService( typeof( IVsSolution ) ) ).GetProjectOfUniqueName( project.UniqueName, out projectHierarchy ); |
| 37 | ············return projectHierarchy; |
| 38 | ········} |
| 39 | |
| 40 | |
| 41 | ········public static IVsHierarchy GetVsHierarchy( this Project project ) |
| 42 | ········{ |
| 43 | ············IVsHierarchy projectHierarchy; |
| 44 | ············project.GetItemInfo( out projectHierarchy, out _, out _ ); |
| 45 | |
| 46 | ············return projectHierarchy; |
| 47 | ········} |
| 48 | ····} |
| 49 | } |
| 50 |
New Commit (33e9857)
| 1 | using System; |
| 2 | using System. IO; |
| 3 | using Microsoft.VisualStudio.Shell.Interop; |
| 4 | |
| 5 | namespace NDOVsPackage |
| 6 | { |
| 7 | ····internal static class ProjectExtensions |
| 8 | ····{ |
| 9 | ········public static EnvDTE.Project DteProject( this Project project ) |
| 10 | ········{ |
| 11 | ············ThreadHelper.ThrowIfNotOnUIThread(); |
| 12 | |
| 13 | ············var projects = ApplicationObject.VisualStudioApplication.Solution.Projects; |
| 14 | ············EnvDTE.Project dteProj = null; |
| 15 | ············foreach (EnvDTE.Project proj in projects) |
| 16 | ············{ |
| 17 | ················if (proj.Name == project.Name) |
| 18 | ················{ |
| 19 | ····················dteProj = proj; |
| 20 | ····················break; |
| 21 | ················} |
| 22 | ············} |
| 23 | |
| 24 | ············return dteProj; |
| 25 | ········} |
| 26 | |
| 27 | ········public static string DefaultMappingFileName( this Project project ) |
| 28 | ········{ |
| 29 | ············return Path.Combine( Path.GetDirectoryName(project.FullPath), "NDOMapping.xml" ); |
| 30 | ········} |
| 31 | |
| 32 | |
| 33 | ········public static string MappingFilePath( this Project project ) |
| 34 | ········{ |
| 35 | ············string defaultFileName = project.DefaultMappingFileName(); |
| 36 | ············if (File.Exists( defaultFileName )) |
| 37 | ················return defaultFileName; |
| 38 | ············ThreadHelper.ThrowIfNotOnUIThread(); |
| 39 | ············var assemblyName = project.DteProject().Properties.Item( "AssemblyName" ).Value; |
| 40 | ············if (assemblyName == null) |
| 41 | ················return null; |
| 42 | ············string mappingFile = Path.Combine( project.FullPath, assemblyName + "ndo.xml" ); |
| 43 | ············if (File.Exists( mappingFile )) |
| 44 | ················return mappingFile; |
| 45 | ············return null; |
| 46 | ········} |
| 47 | |
| 48 | |
| 49 | ········public static string DefaultMappingFileName( this EnvDTE.Project project ) |
| 50 | ········{ |
| 51 | ············ThreadHelper.ThrowIfNotOnUIThread(); |
| 52 | ············return Path.Combine( Path.GetDirectoryName( project.FullName ), "NDOMapping.xml" ); |
| 53 | ········} |
| 54 | |
| 55 | |
| 56 | ········public static string MappingFilePath( this EnvDTE.Project project ) |
| 57 | ········{ |
| 58 | ············string defaultFileName = project.DefaultMappingFileName(); |
| 59 | ············if (File.Exists( defaultFileName )) |
| 60 | ················return defaultFileName; |
| 61 | ············ThreadHelper.ThrowIfNotOnUIThread(); |
| 62 | ············var assemblyName = project.Properties.Item( "AssemblyName" ).Value; |
| 63 | ············if (assemblyName == null) |
| 64 | ················return null; |
| 65 | ············string mappingFile = Path.Combine( project.FullName, assemblyName + "ndo.xml" ); |
| 66 | ············if (File.Exists( mappingFile )) |
| 67 | ················return mappingFile; |
| 68 | ············return null; |
| 69 | ········} |
| 70 | |
| 71 | |
| 72 | ········public static bool MappingFileExists(this Project project ) |
| 73 | ········{ |
| 74 | ············return project.MappingFilePath() != null; |
| 75 | ········} |
| 76 | |
| 77 | ········public static IVsHierarchy GetVsHierarchy( this EnvDTE.Project project ) |
| 78 | ········{ |
| 79 | ············ThreadHelper.ThrowIfNotOnUIThread(); |
| 80 | ············IVsHierarchy projectHierarchy = null; |
| 81 | |
| 82 | ············( (IVsSolution) Package.GetGlobalService( typeof( IVsSolution ) ) ).GetProjectOfUniqueName( project.UniqueName, out projectHierarchy ); |
| 83 | ············return projectHierarchy; |
| 84 | ········} |
| 85 | |
| 86 | |
| 87 | ········public static IVsHierarchy GetVsHierarchy( this Project project ) |
| 88 | ········{ |
| 89 | ············IVsHierarchy projectHierarchy; |
| 90 | ············project.GetItemInfo( out projectHierarchy, out _, out _ ); |
| 91 | |
| 92 | ············return projectHierarchy; |
| 93 | ········} |
| 94 | ····} |
| 95 | } |
| 96 |