Skip to content

Instantly share code, notes, and snippets.

@ChuckSavage
Created February 10, 2013 18:59
Show Gist options
  • Save ChuckSavage/4750630 to your computer and use it in GitHub Desktop.
Save ChuckSavage/4750630 to your computer and use it in GitHub Desktop.
Paths utility file for adding params to a string Combine.
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