/[gr2lib]/trunk/gr2lib/core/coretypes/implementation/FilePath.cs
ViewVC logotype

Contents of /trunk/gr2lib/core/coretypes/implementation/FilePath.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 79 - (show annotations) (download)
Thu Jul 15 21:50:56 2010 UTC (9 years, 11 months ago) by william
File size: 1684 byte(s)
create and implement interfaces for all core classes (for type casting)

1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using gr2lib.core.interfaces;
5
6 namespace gr2lib.core.coretypes.implementation
7 {
8
9 public class FilePath : IFilePath
10 {
11 #region implicit Conversion
12 public static implicit operator FilePath(string str)
13 {
14 return new FilePath(str);
15 }
16 public static implicit operator string(FilePath path)
17 {
18 return path.FullPath;
19 }
20 #endregion
21
22 private string FileNameFromPath(string path)
23 {
24 int lastSlash = path.LastIndexOf('\\');
25 if (lastSlash > 0) return path.Substring(lastSlash + 1);
26 lastSlash = path.LastIndexOf('/');
27 if (lastSlash > 0) return path.Substring(lastSlash + 1);
28 return path;
29 }
30 private string FileDirFromPath(string path)
31 {
32 int lastSlash = path.LastIndexOf('\\');
33 if (lastSlash > 0) return path.Substring(0, lastSlash);
34 lastSlash = path.LastIndexOf('/');
35 if (lastSlash > 0) return path.Substring(0, lastSlash);
36 return path;
37 }
38
39 private string _filename;
40 public FilePath()
41 {
42 _filename = "";
43 }
44 public FilePath(string filename)
45 {
46 _filename = filename;
47 }
48 #region IFilePath Members
49 public string FullPath { get { return _filename; } }
50 public string Path { get { return FileDirFromPath(FullPath); } }
51 public string Name { get { return FileNameFromPath(FullPath); } }
52 #endregion
53 }
54 }

  ViewVC Help
Powered by ViewVC 1.1.22