CloneFile( CollatedObject collatedFile, System.Collections.Generic.Dictionary <CollatedObject, Bam.Core.Module> referenceMap) { var clonedFile = Bam.Core.Module.Create <CollatedFile>(preInitCallback: module => { Bam.Core.TokenizedString referenceFilePath = null; if (collatedFile.Reference != null) { if (!referenceMap.ContainsKey(collatedFile.Reference)) { throw new Bam.Core.Exception("Unable to find CollatedFile reference to {0} in the reference map", collatedFile.Reference.SourceModule.ToString()); } var newRef = referenceMap[collatedFile.Reference]; // the PathKey depends on whether the reference came straight as a clone, or after being stripped referenceFilePath = newRef.GeneratedPaths[this.ReferenceKey]; } module.Macros["CopyDir"] = Collation.GenerateFileCopyDestination( this, referenceFilePath, collatedFile.SubDirectory, this.GeneratedPaths[Key]); }); this.DependsOn(clonedFile); clonedFile.SourceModule = collatedFile; clonedFile.SourcePath = collatedFile.GeneratedPaths[CollatedObject.Key]; clonedFile.SubDirectory = collatedFile.SubDirectory; if (collatedFile.Reference == null) { referenceMap.Add(collatedFile, clonedFile); this.ReferenceKey = CollatedObject.Key; } }