Take this non-compiling code for instance:
public string GetPath(string basefolder, string[] extraFolders) { string version = Versioner.GetBuildAndDotNetVersions(); string callingModule = StackCrawler.GetCallingModuleName(); return AppendFolders(basefolder, version, callingModule, extraFolders); } private string AppendFolders(params string[] folders) { string outstring = folders[0]; for (int i = 1; i < folders.Length; i++) { string fixedPath = folders[i][0] == '\\' ? folders[i].Substring(1) : folders[i]; Path.Combine(outstring, fixedPath); } return outstring; }
This example is a somewhat simplified version of testing code I am using. Please, I am only interested in solutions having directly to do with the param keyword. I know how lists and other similar things work.
Is there a way to ‘explode’ the extraFolders array so that it’s contents can be passed into AppendFolders along with other parameters?
One option is to make the
paramsparameter anobject[]:If you want something more strongly-typed, another option is to create a custom union type with implicit conversion operators:
In either case, this will compile: