public static bool TryGetScriptsInDirectory(string root, string path, out ScriptInfo[] scripts) { // assert: root is not suffixed with directory separator // trim leading {root} path: if (!string.IsNullOrEmpty(root) && path.StartsWith(root, CurrentPlatform.PathStringComparison)) { if (path.Length == root.Length) { path = string.Empty; } else if (path[root.Length] == CurrentPlatform.DirectorySeparator) { path = (path.Length > root.Length + 1) ? path.Substring(root.Length + 1) : string.Empty; } else { scripts = Array.Empty <ScriptInfo>(); return(false); } } // try to get compiled scripts within path: return(ScriptsMap.TryGetDirectory(path, out scripts)); }
/// <summary> /// Gets scripts in given directory. /// </summary> public static bool TryGetScriptsInDirectory(string root, string path, out IEnumerable <ScriptInfo> scripts) { // trim leading {root} path: if (!string.IsNullOrEmpty(root) && path.StartsWith(root, StringComparison.Ordinal)) { if (path.Length == root.Length) { path = string.Empty; } else if (path[root.Length] == CurrentPlatform.DirectorySeparator) { path = path.Remove(root.Length + 1); } else if (root[root.Length - 1] == CurrentPlatform.DirectorySeparator) { path = path.Remove(root.Length); } } // try to get compiled scripts within path: return(ScriptsMap.TryGetDirectory(path, out scripts)); }
/// <summary> /// Gets scripts in given directory. /// </summary> public static bool TryGetScriptsInDirectory(string root, string path, out IEnumerable <ScriptInfo> scripts) { // trim leading {root} path: if (!string.IsNullOrEmpty(root) && path.StartsWith(root, StringComparison.Ordinal)) // TODO: CurrentPlatform comparer { if (path.Length == root.Length) { path = string.Empty; } else if (path[root.Length] == CurrentPlatform.DirectorySeparator) { path = (path.Length > root.Length + 1) ? path.Substring(root.Length + 1) : string.Empty; } else { scripts = Enumerable.Empty <ScriptInfo>(); return(false); } } // try to get compiled scripts within path: return(ScriptsMap.TryGetDirectory(path, out scripts)); }