diff --git a/ICSharpCode.NRefactory.CSharp/CSharpProjectContent.cs b/ICSharpCode.NRefactory.CSharp/CSharpProjectContent.cs index bdc2040490..e3429861c2 100644 --- a/ICSharpCode.NRefactory.CSharp/CSharpProjectContent.cs +++ b/ICSharpCode.NRefactory.CSharp/CSharpProjectContent.cs @@ -87,7 +87,7 @@ namespace ICSharpCode.NRefactory.CSharp return null; } - public ICompilation CreateCompilation() + public virtual ICompilation CreateCompilation() { var solutionSnapshot = new DefaultSolutionSnapshot(); ICompilation compilation = new SimpleCompilation(solutionSnapshot, this, assemblyReferences); @@ -95,28 +95,33 @@ namespace ICSharpCode.NRefactory.CSharp return compilation; } - public ICompilation CreateCompilation(ISolutionSnapshot solutionSnapshot) + public virtual ICompilation CreateCompilation(ISolutionSnapshot solutionSnapshot) { return new SimpleCompilation(solutionSnapshot, this, assemblyReferences); } + protected virtual CSharpProjectContent Clone() + { + return new CSharpProjectContent(this); + } + public IProjectContent SetAssemblyName(string newAssemblyName) { - CSharpProjectContent pc = new CSharpProjectContent(this); + CSharpProjectContent pc = Clone(); pc.assemblyName = newAssemblyName; return pc; } public IProjectContent AddAssemblyReferences(IEnumerable references) { - CSharpProjectContent pc = new CSharpProjectContent(this); + CSharpProjectContent pc = Clone(); pc.assemblyReferences.AddRange(references); return pc; } public IProjectContent RemoveAssemblyReferences(IEnumerable references) { - CSharpProjectContent pc = new CSharpProjectContent(this); + CSharpProjectContent pc = Clone(); pc.assemblyReferences.RemoveAll(r => references.Contains(r)); return pc; } @@ -129,7 +134,7 @@ namespace ICSharpCode.NRefactory.CSharp if (!Platform.FileNameComparer.Equals(oldFile.FileName, newFile.FileName)) throw new ArgumentException("When both oldFile and newFile are specified, they must use the same file name."); } - CSharpProjectContent pc = new CSharpProjectContent(this); + CSharpProjectContent pc = Clone(); if (newFile == null) pc.parsedFiles.Remove(oldFile.FileName); else @@ -139,7 +144,7 @@ namespace ICSharpCode.NRefactory.CSharp public IProjectContent UpdateProjectContent(IEnumerable oldFiles, IEnumerable newFiles) { - CSharpProjectContent pc = new CSharpProjectContent(this); + CSharpProjectContent pc = Clone(); if (oldFiles != null) { foreach (var oldFile in oldFiles) { pc.parsedFiles.Remove(oldFile.FileName);