/// <summary> /// Dynamizes a list of files. /// </summary> /// <param name="files">The files to dynamize.</param> /// <param name="outDir">The output directory or <B>null</B>.</param> static void DynamizeFiles(List <string> files, string outDir) { Dynamizer dynamizer = new Dynamizer(); foreach (string file in files) { Console.WriteLine("Dynamizing types in '{0}'", file); IParser parser; CompilationUnit unit; string ext = Path.GetExtension(file).ToLower(); using (StreamReader sr = new StreamReader(file)) { switch (ext) { case ".cs": parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, sr); break; case ".vb": parser = ParserFactory.CreateParser(SupportedLanguage.VBNet, sr); break; default: throw new ArgumentException("Unknown language."); } parser.ParseMethodBodies = true; parser.Parse(); if (parser.Errors.count > 0) { throw new ArgumentException("Parse error."); } unit = parser.CompilationUnit; } unit = dynamizer.Dynamize(unit); string out_path = Path.ChangeExtension(file, ".dynamic" + Path.GetExtension(file)); if (outDir != null) { out_path = Path.Combine(outDir, Path.GetFileName(out_path)); } try { using (StreamWriter sw = new StreamWriter(out_path)) { IOutputASTVisitor visitor; switch (ext) { case ".cs": { sw.WriteLine("// ***"); sw.WriteLine("// Do not edit this file. It has been generated by the ClassDynamizer tool."); sw.WriteLine("// ***"); sw.WriteLine("#pragma warning disable 0108"); visitor = new CSharpOutputVisitor(); break; } case ".vb": { sw.WriteLine("' ***"); sw.WriteLine("' Do not edit this file. It has been generated by the ClassDynamizer tool."); sw.WriteLine("' ***"); visitor = new VBNetOutputVisitor(); break; } default: throw new ArgumentException("Unknown language."); } unit.AcceptVisitor(visitor, DBNull.Value); sw.Write(visitor.Text); } } catch (UnauthorizedAccessException) { Console.WriteLine("Could not write to '{0}'. Is the file checked out?", out_path); } } }
/// <summary> /// Dynamizes a list of files. /// </summary> /// <param name="files">The files to dynamize.</param> /// <param name="outDir">The output directory or <B>null</B>.</param> static void DynamizeFiles(List<string> files, string outDir) { Dynamizer dynamizer = new Dynamizer(); foreach (string file in files) { Console.WriteLine("Dynamizing types in '{0}'", file); IParser parser; CompilationUnit unit; string ext = Path.GetExtension(file).ToLower(); using (StreamReader sr = new StreamReader(file)) { switch (ext) { case ".cs": parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, sr); break; case ".vb": parser = ParserFactory.CreateParser(SupportedLanguage.VBNet, sr); break; default: throw new ArgumentException("Unknown language."); } parser.ParseMethodBodies = true; parser.Parse(); if (parser.Errors.count > 0) { throw new ArgumentException("Parse error."); } unit = parser.CompilationUnit; } unit = dynamizer.Dynamize(unit); string out_path = Path.ChangeExtension(file, ".dynamic" + Path.GetExtension(file)); if (outDir != null) out_path = Path.Combine(outDir, Path.GetFileName(out_path)); try { using (StreamWriter sw = new StreamWriter(out_path)) { IOutputASTVisitor visitor; switch (ext) { case ".cs": { sw.WriteLine("// ***"); sw.WriteLine("// Do not edit this file. It has been generated by the ClassDynamizer tool."); sw.WriteLine("// ***"); sw.WriteLine("#pragma warning disable 0108"); visitor = new CSharpOutputVisitor(); break; } case ".vb": { sw.WriteLine("' ***"); sw.WriteLine("' Do not edit this file. It has been generated by the ClassDynamizer tool."); sw.WriteLine("' ***"); visitor = new VBNetOutputVisitor(); break; } default: throw new ArgumentException("Unknown language."); } unit.AcceptVisitor(visitor, DBNull.Value); sw.Write(visitor.Text); } } catch (UnauthorizedAccessException) { Console.WriteLine("Could not write to '{0}'. Is the file checked out?", out_path); } } }