Exemplo n.º 1
0
 void RunTest(string c_code, string expectedXml)
 {
     StringReader reader = null;
     StringWriter writer = null;
     try
     {
         reader = new StringReader(c_code);
         writer = new StringWriter();
         var xWriter = new XmlnsHidingWriter(writer)
         {
             Formatting = Formatting.Indented
         };
         var xc = new XmlConverter(reader, xWriter);
         xc.Convert();
         writer.Flush();
         Assert.AreEqual(expectedXml, writer.ToString());
     }
     catch
     {
         Debug.WriteLine(writer.ToString());
         throw;
     }
     finally
     {
         if (writer != null)
             writer.Dispose();
         if (reader != null)
             reader.Dispose();
     }
 }
Exemplo n.º 2
0
 public int Execute(string []args)
 {
     TextReader input = Console.In;
     TextWriter output = Console.Out;
     if (args.Length > 2)
     {
         Usage();
         return 1;
     }
     if (args.Length >= 1)
     {
         try
         {
             input = new StreamReader(args[0]);
         }
         catch (Exception ex)
         {
             Console.Error.WriteLine("c2xml: Unable to open file {0} for reading. {1}", args[0], ex.Message);
             return 1;
         }
     }
     if (args.Length == 2)
     {
         try
         {
             output = new StreamWriter(args[1]);
         }
         catch (Exception ex)
         {
             Console.Error.WriteLine("c2xml: Unable to open file {0} for writing. {1}", args[1], ex.Message);
             return 1;
         }
     }
     var xWriter = new XmlTextWriter(output)
     {
         Formatting = Formatting.Indented
     };
     XmlConverter c = new XmlConverter(input, xWriter);
     c.Convert();
     output.Flush();
     return 0;
 }