Ejemplo n.º 1
0
        string InternalStandardize(string code)
        {
            var    reader           = new StringReader(code);
            var    licenseReader    = new StringReader(licenseHeader);
            var    usingStatements  = new List <string>();
            var    writer           = new StringWriter();
            string codeLine         = null;
            bool   isLicensePresent = true;

            foreach (var licenseLine in licenseReader.AsLines())
            {
                if (isLicensePresent)
                {
                    codeLine = reader.ReadLine();
                }
                writer.WriteLine(licenseLine);
                isLicensePresent = codeLine == licenseLine;
            }
            // If the license wasn't present, we have a line we need to push back onto the reader
            var lines = isLicensePresent
                                ? reader.AsLines()
                                : Prepend(codeLine, reader.AsLines());
            bool hasEncounteredNamespace = false;

            foreach (var sourceLine in lines)
            {
                if (usingStatements != null)
                {
                    usingStatements = ProcessUsingStatements(writer, usingStatements, ref hasEncounteredNamespace, sourceLine);
                }
                else
                {
                    writer.WriteLine(Tabify(sourceLine));
                }
            }
            if (usingStatements != null)
            {
                throw new Exception("Using statements were never dealt with.");
            }
            return(writer.ToString());
        }
Ejemplo n.º 2
0
 public static IEnumerable <string> AsLines(this string content)
 {
     using (var reader = new StringReader(content)) {
         return(reader.AsLines().ToList());
     }
 }