PageRenderTime 46ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/src/NUnit/util/RecentFileEntry.cs

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