private static int Main(string[] args) { string language; string infilename; string outfilename; TargetLanguage targetLanguage; if (args.Length != 3) { Console.Error.WriteLine("Usage: \"{0} <language> <input> <output>\", where <language> is \"VB\" or \"CSharp\"", Path.GetFileNameWithoutExtension(Environment.GetCommandLineArgs()[0])); return(1); } language = args[0]; infilename = args[1]; outfilename = args[2]; switch (language) { case "VB": targetLanguage = TargetLanguage.VB; break; case "CSharp": case "C#": targetLanguage = TargetLanguage.CSharp; break; default: Console.Error.WriteLine("Language must be \"VB\" or \"CSharp\""); return(1); } var serializer = new XmlSerializer(typeof(Tree)); serializer.UnknownAttribute += new XmlAttributeEventHandler(serializer_UnknownAttribute); serializer.UnknownElement += new XmlElementEventHandler(serializer_UnknownElement); serializer.UnknownNode += new XmlNodeEventHandler(serializer_UnknownNode); serializer.UnreferencedObject += new UnreferencedObjectEventHandler(serializer_UnreferencedObject); Tree tree; using (var reader = new XmlTextReader(infilename) { DtdProcessing = DtdProcessing.Prohibit, XmlResolver = null }) { tree = (Tree)serializer.Deserialize(reader); } using (var outfile = new StreamWriter(File.Open(outfilename, FileMode.Create))) { BoundNodeClassWriter.Write(outfile, tree, targetLanguage); } return(0); }
static void Main(string[] args) { var nonSwitches = args.Where(a => !a.StartsWith("/")).ToArray(); string language; string infilename; string outfilename; TargetLanguage targetLanguage; if (nonSwitches.Length != 3) { Console.WriteLine("Usage: \"{0} <language> <input> <output>\", where <language> is \"VB\" or \"CSharp\" or \"Java\"", Path.GetFileNameWithoutExtension(Environment.GetCommandLineArgs()[0])); return; } language = args[0]; infilename = args[1]; outfilename = args[2]; switch (language) { case "VB": targetLanguage = TargetLanguage.VB; break; case "CSharp": case "C#": targetLanguage = TargetLanguage.CSharp; break; case "Java": targetLanguage = TargetLanguage.Java; break; default: Console.WriteLine("Language must be \"VB\" or \"CSharp\" or \"Java\""); return; } var serializer = new XmlSerializer(typeof(Tree)); serializer.UnknownAttribute += new XmlAttributeEventHandler(serializer_UnknownAttribute); serializer.UnknownElement += new XmlElementEventHandler(serializer_UnknownElement); serializer.UnknownNode += new XmlNodeEventHandler(serializer_UnknownNode); serializer.UnreferencedObject += new UnreferencedObjectEventHandler(serializer_UnreferencedObject); Tree tree; using (var reader = new XmlTextReader(infilename)) { tree = (Tree)serializer.Deserialize(reader); } using (var outfile = new StreamWriter(File.Open(outfilename, FileMode.Create))) { BoundNodeClassWriter.Write(outfile, tree, targetLanguage); } }
private static int Main(string[] args) { string language; string infilename; string outfilename; TargetLanguage targetLanguage; if (args.Length != 3) { Console.Error.WriteLine("Usage: \"{0} <language> <input> <output>\", where <language> is \"VB\" or \"CSharp\"", Path.GetFileNameWithoutExtension(args[0])); return(1); } language = args[0]; infilename = args[1]; outfilename = args[2]; switch (language) { case "VB": targetLanguage = TargetLanguage.VB; break; case "CSharp": case "C#": targetLanguage = TargetLanguage.CSharp; break; default: Console.Error.WriteLine("Language must be \"VB\" or \"CSharp\""); return(1); } Tree tree; var serializer = new XmlSerializer(typeof(Tree)); using (var reader = XmlReader.Create(infilename, new XmlReaderSettings { DtdProcessing = DtdProcessing.Prohibit })) { tree = (Tree)serializer.Deserialize(reader); } using (var outfile = new StreamWriter(File.Open(outfilename, FileMode.Create), Encoding.UTF8)) { BoundNodeClassWriter.Write(outfile, tree, targetLanguage); } return(0); }