77 * of patent rights can be found in the PATENTS file in the same directory.
88 */
99
10+ using System . Collections . Generic ;
1011using System . IO ;
12+ using System . Linq ;
1113using System . Text ;
1214
1315namespace React
@@ -17,19 +19,35 @@ namespace React
1719 /// </summary>
1820 abstract public class FileSystemBase : IFileSystem
1921 {
22+ /// <summary>
23+ /// Prefix for relative paths
24+ /// </summary>
25+ public const string RELATIVE_PREFIX = "~/" ;
26+
2027 /// <summary>
2128 /// Converts a path from an application relative path (~/...) to a full filesystem path
2229 /// </summary>
2330 /// <param name="relativePath">App-relative path of the file</param>
2431 /// <returns>Full path of the file</returns>
2532 public abstract string MapPath ( string relativePath ) ;
2633
34+ /// <summary>
35+ /// Converts a path from a full filesystem path to anan application relative path (~/...)
36+ /// </summary>
37+ /// <param name="absolutePath">Full path of the file</param>
38+ /// <returns>App-relative path of the file</returns>
39+ public virtual string ToRelativePath ( string absolutePath )
40+ {
41+ var root = MapPath ( RELATIVE_PREFIX ) ;
42+ return absolutePath . Replace ( root , RELATIVE_PREFIX ) . Replace ( '\\ ' , '/' ) ;
43+ }
44+
2745 /// <summary>
2846 /// Reads the contents of a file as a string.
2947 /// </summary>
3048 /// <param name="relativePath">App-relative path of the file</param>
3149 /// <returns>Contents of the file</returns>
32- public string ReadAsString ( string relativePath )
50+ public virtual string ReadAsString ( string relativePath )
3351 {
3452 return File . ReadAllText ( MapPath ( relativePath ) , Encoding . UTF8 ) ;
3553 }
@@ -39,7 +57,7 @@ public string ReadAsString(string relativePath)
3957 /// </summary>
4058 /// <param name="relativePath">App-relative path of the file</param>
4159 /// <param name="contents">Contents of the file</param>
42- public void WriteAsString ( string relativePath , string contents )
60+ public virtual void WriteAsString ( string relativePath , string contents )
4361 {
4462 File . WriteAllText ( MapPath ( relativePath ) , contents , Encoding . UTF8 ) ;
4563 }
@@ -49,9 +67,21 @@ public void WriteAsString(string relativePath, string contents)
4967 /// </summary>
5068 /// <param name="relativePath">App-relative path of the file</param>
5169 /// <returns><c>true</c> if the file exists</returns>
52- public bool FileExists ( string relativePath )
70+ public virtual bool FileExists ( string relativePath )
5371 {
5472 return File . Exists ( MapPath ( relativePath ) ) ;
5573 }
74+
75+ /// <summary>
76+ /// Gets all the file paths that match the specified pattern
77+ /// </summary>
78+ /// <param name="glob">Pattern to search for (eg. "~/Scripts/*.js")</param>
79+ /// <returns>File paths that match the pattern</returns>
80+ public virtual IEnumerable < string > Glob ( string glob )
81+ {
82+ var path = MapPath ( Path . GetDirectoryName ( glob ) ) ;
83+ var searchPattern = Path . GetFileName ( glob ) ;
84+ return Directory . EnumerateFiles ( path , searchPattern ) . Select ( ToRelativePath ) ;
85+ }
5686 }
5787}
0 commit comments