/src/NUnit/util/ProjectConverters/VisualStudioConverter.cs
C# | 67 lines | 55 code | 4 blank | 8 comment | 3 complexity | 5208fdebe8867ae67377663d72b7c642 MD5 | raw file
1// **************************************************************** 2// Copyright 2008, Charlie Poole 3// This is free software licensed under the NUnit license. You may 4// obtain a copy of the license at http://nunit.org 5// **************************************************************** 6using System; 7using System.IO; 8using NUnit.Core; 9using NUnit.Core.Extensibility; 10using NUnit.Util.Extensibility; 11 12namespace NUnit.Util.ProjectConverters 13{ 14 /// <summary> 15 /// Summary description for VSProjectLoader. 16 /// </summary> 17 public class VisualStudioConverter : IProjectConverter 18 { 19 #region IProjectConverter Members 20 21 public bool CanConvertFrom(string path) 22 { 23 return VSProject.IsProjectFile(path)|| VSProject.IsSolutionFile(path); 24 } 25 26 public NUnitProject ConvertFrom(string path) 27 { 28 NUnitProject project = new NUnitProject( Path.GetFullPath( path ) ); 29 30 if ( VSProject.IsProjectFile(path) ) 31 { 32 VSProject vsProject = new VSProject( path ); 33 project.Add( vsProject ); 34 } 35 else if ( VSProject.IsSolutionFile(path) ) 36 { 37 string solutionDirectory = Path.GetDirectoryName( path ); 38 using(StreamReader reader = new StreamReader( path )) 39 { 40 char[] delims = { '=', ',' }; 41 char[] trimchars = { ' ', '"' }; 42 43 string line = reader.ReadLine(); 44 while ( line != null ) 45 { 46 if ( line.StartsWith( "Project" ) ) 47 { 48 string[] parts = line.Split( delims ); 49 string vsProjectPath = parts[2].Trim(trimchars); 50 51 if ( VSProject.IsProjectFile( vsProjectPath ) ) 52 project.Add( new VSProject( Path.Combine( solutionDirectory, vsProjectPath ) ) ); 53 } 54 55 line = reader.ReadLine(); 56 } 57 } 58 } 59 60 project.IsDirty = false; 61 62 return project; 63 } 64 65 #endregion 66 } 67}