private static void SaveToFile(FileSystemInfo outputDirInfo, FunctionContents functionContents) { var saveToFile = new FileInfo(Path.Combine(outputDirInfo.FullName, functionContents.FileNameFriendlyName())); var writer = new StreamWriter(saveToFile.FullName); writer.WriteLine(functionContents.Name); writer.WriteLine(" {"); foreach (var line in functionContents.Lines) { writer.WriteLine(line); } writer.WriteLine(" }"); writer.Flush(); writer.Close(); }
private static List<FunctionContents> ParseFunctionLines(FileItem fileItem) { int linesCount = 1; int currentLevel = 0; int namespaceLevel = 1; int classLevel = 2; const int functionLevel = 3; FunctionContents currentFunction = null; List<FunctionContents> functionContentCol = new List<FunctionContents>(); List<string> previousLines = new List<string>(); using (TextReader reader = new StreamReader(fileItem.TheFile.FullName)) { var line = reader.ReadLine(); while (line != null) { if (line.Trim().StartsWith("}")) currentLevel--; else if (line.Trim().StartsWith("{")) currentLevel++; if (currentLevel >= functionLevel) { if (currentFunction == null) { // enter function currentFunction = new FunctionContents(GetFunctionLine(previousLines)); functionContentCol.Add(currentFunction); } else currentFunction.Lines.Add(line); } else { currentFunction = null; } linesCount++; previousLines.Add(line); line = reader.ReadLine(); } } Console.WriteLine("Lines read: {0}", linesCount); return functionContentCol; }