PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/src/NUnit/util/RecentFileEntry.cs

#
C# | 74 lines | 54 code | 14 blank | 6 comment | 3 complexity | 75797e6e189670548abe94ef7a1cd304 MD5 | raw file
 1// ****************************************************************
 2// Copyright 2007, 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// ****************************************************************
 6
 7using System;
 8
 9namespace NUnit.Util
10{
11	public class RecentFileEntry
12	{
13		public static readonly char Separator = ',';
14
15		private string path;
16		
17		private Version clrVersion;
18
19		public RecentFileEntry( string path )
20		{
21			this.path = path;
22			this.clrVersion = Environment.Version;
23		}
24
25		public RecentFileEntry( string path, Version clrVersion )
26		{
27			this.path = path;
28			this.clrVersion = clrVersion;
29		}
30
31		public string Path
32		{
33			get { return path; }
34		}
35
36		public Version CLRVersion
37		{
38			get { return clrVersion; }
39		}
40
41		public bool Exists
42		{
43			get { return path != null && System.IO.File.Exists( path ); }
44		}
45
46		public bool IsCompatibleCLRVersion
47		{
48			get { return clrVersion.Major <= Environment.Version.Major; }
49		}
50
51		public override string ToString()
52		{
53			return Path + Separator + CLRVersion.ToString();
54		}
55
56		public static RecentFileEntry Parse( string text )
57		{
58			int sepIndex = text.LastIndexOf( Separator );
59
60			if ( sepIndex > 0 )
61				try
62				{
63					return new RecentFileEntry( text.Substring( 0, sepIndex ), 
64						new Version( text.Substring( sepIndex + 1 ) ) );
65				}
66				catch
67				{
68					//The last part was not a version, so fall through and return the whole text
69				}
70			
71			return new RecentFileEntry( text );
72		}
73	}
74}