Tuesday, February 5, 2013

Here's a handy little way to resolve and combine paths I use in C#

In a nice little linq one liner with a lambda I handle the null case and aggregate all the paths with root:

public string CombinePaths(string root, params string[] args) 
{
  return Path.GetFullPath(args.Aggregate(root, (current, path) => Path.Combine(current ?? string.Empty, path ?? string.Empty)));
}

No comments: