/// <summary> /// Write the Classes as C# Code /// </summary> /// <param name="inOutPath"></param> /// <param name="tmpClassList"></param> /// <param name="inProjectInformation"></param> /// <param name="tmpReplacer"></param> private static void WriteCSharpCode(string inOutPath, ProjectInformation inProjectInformation, List <StringReplacement> inReplacementList) { var tmpWriter = new CSharpClassWriter(); //Predo StringReplacements var tmpList = new List <Tuple <Regex, StringReplacement> >(); foreach (var tmpEntry in inReplacementList) { tmpList.Add(new Tuple <Regex, StringReplacement> ( new Regex(tmpEntry.NameRegex, RegexOptions.Compiled) , tmpEntry )); } foreach (var tmpClass in inProjectInformation.ClassList) { if (tmpClass.ClassType == ClassTypeEnum.System) { continue; } NamespaceHelper.HandleNamespaces(tmpClass); var tmpCSharp = tmpWriter.CreateClassFile(tmpClass).Content; foreach (var tmpReplacement in tmpList) { if (tmpReplacement.Item1.IsMatch(tmpClass.Name)) { if (!string.IsNullOrEmpty(tmpReplacement.Item2.RequiredUsing)) { if (tmpCSharp.Contains(tmpReplacement.Item2.SourceText) && !tmpCSharp.Contains(tmpReplacement.Item2.RequiredUsing)) { tmpCSharp = $"using {tmpReplacement.Item2.RequiredUsing};{Environment.NewLine}{tmpCSharp}"; } } tmpCSharp = tmpCSharp.Replace(tmpReplacement.Item2.SourceText, tmpReplacement.Item2.ReplacementText); } } var tmpNewNamespace = tmpClass.Namespace.Split('.'); var tmpNewPath = Path.Combine(inOutPath, Path.Combine(tmpNewNamespace)); Directory.CreateDirectory(tmpNewPath); File.WriteAllText(Path.Combine(tmpNewPath, tmpClass.Name + ".cs"), tmpCSharp); } //Write UnknownType File var tmpUnknownFilePaths = new List <string>(); var tmpUsings = new List <string>(); foreach (var tmpClass in inProjectInformation.GetAllUnknownTypes()) { var tmpCSharp = new StringBuilder(); tmpClass.ModifierList.Add("public"); tmpClass.ModifierList.Add("class"); new CSharpClassWriter().AddClassContainerString(tmpClass, tmpCSharp, 1); tmpUnknownFilePaths.Add(tmpCSharp.ToString()); } //Write unknown Types into File var tmpUnknownFile = $@" {string.Join(Environment.NewLine, tmpUsings.OrderBy(inItem => inItem).Select(inItem => $"using {inItem};"))} namespace UnknownTypes {{ {string.Join(Environment.NewLine + Environment.NewLine, tmpUnknownFilePaths)} }}"; Directory.CreateDirectory(Path.Combine(inOutPath)); File.WriteAllText(Path.Combine(inOutPath, "UnknownTypes.cs"), tmpUnknownFile); }