Created
February 10, 2013 18:59
-
-
Save ChuckSavage/4750630 to your computer and use it in GitHub Desktop.
Paths utility file for adding params to a string Combine.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Paths | |
{ | |
/// <summary> | |
/// Apply Path.Combine(on path and list) | |
/// </summary> | |
/// <param name="path"></param> | |
/// <param name="list"></param> | |
/// <returns></returns> | |
public static string Combine(string path, params string[] list) | |
{ | |
List<string> value = list.ToList(); | |
value.Insert(0, path); | |
return Combine(value.ToArray()); | |
} | |
/// <summary> | |
/// Apply Path.Combine on the list. | |
/// </summary> | |
/// <param name="list"></param> | |
/// <returns></returns> | |
public static string Combine(params string[] list) | |
{ | |
if (null == list) | |
throw new ArgumentNullException("Argument to method cannot be null"); | |
string path = string.Empty; | |
for (int i = 0; i < list.Length; i++) | |
if (!string.IsNullOrEmpty(list[i])) | |
path = Path.Combine(path, list[i]); | |
return path; | |
} | |
/// <summary> | |
/// Apply Path.Combine on the list. | |
/// </summary> | |
/// <param name="list"></param> | |
/// <returns></returns> | |
public static string Combine(IEnumerable<string> list) | |
{ | |
if (null == list) | |
throw new ArgumentNullException("Argument to method cannot be null"); | |
return Combine(list.ToArray()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment