From 6cf7b10c54c621f3f4b52f70c80c568badc6ae5d Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 27 Jan 2016 12:07:24 +0100 Subject: [PATCH] [mono-api-info] Add support for writing output to a file specified using a command line argument. --- mcs/tools/corcompare/mono-api-info.cs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/mcs/tools/corcompare/mono-api-info.cs b/mcs/tools/corcompare/mono-api-info.cs index c43437fe40d..0886d14b3bd 100644 --- a/mcs/tools/corcompare/mono-api-info.cs +++ b/mcs/tools/corcompare/mono-api-info.cs @@ -31,6 +31,7 @@ namespace CorCompare bool showHelp = false; AbiMode = false; FollowForwarders = false; + string output = null; var acoll = new AssemblyCollection (); @@ -52,6 +53,9 @@ namespace CorCompare { "r=", "Read and register the file {ASSEMBLY}, and add the directory containing ASSEMBLY to the search path.", v => TypeHelper.Resolver.ResolveFile (v) }, + { "o=", + "The output file. If not specified the output will be written to stdout.", + v => output = v }, { "h|?|help", "Show this message and exit.", v => showHelp = v != null }, @@ -93,10 +97,18 @@ namespace CorCompare acoll.Document = doc; acoll.DoOutput (); - var writer = new WellFormedXmlWriter (new XmlTextWriter (Console.Out) { Formatting = Formatting.Indented }); - XmlNode decl = doc.CreateXmlDeclaration ("1.0", "utf-8", null); - doc.InsertBefore (decl, doc.DocumentElement); - doc.WriteTo (writer); + TextWriter outputStream = null; + if (!string.IsNullOrEmpty (output)) + outputStream = new StreamWriter (output); + try { + var writer = new WellFormedXmlWriter (new XmlTextWriter (outputStream ?? Console.Out) { Formatting = Formatting.Indented }); + XmlNode decl = doc.CreateXmlDeclaration ("1.0", "utf-8", null); + doc.InsertBefore (decl, doc.DocumentElement); + doc.WriteTo (writer); + } finally { + if (outputStream != null) + outputStream.Dispose (); + } return 0; } -- 2.25.1