aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/ProtoDump/Program.cs
diff options
context:
space:
mode:
Diffstat (limited to 'csharp/src/ProtoDump/Program.cs')
-rw-r--r--csharp/src/ProtoDump/Program.cs36
1 files changed, 12 insertions, 24 deletions
diff --git a/csharp/src/ProtoDump/Program.cs b/csharp/src/ProtoDump/Program.cs
index a935e780..ebe4255d 100644
--- a/csharp/src/ProtoDump/Program.cs
+++ b/csharp/src/ProtoDump/Program.cs
@@ -37,7 +37,7 @@
using System;
using System.IO;
-namespace Google.ProtocolBuffers.ProtoDump
+namespace Google.Protobuf.ProtoDump
{
/// <summary>
/// Small utility to load a binary message and dump it in text form
@@ -53,36 +53,24 @@ namespace Google.ProtocolBuffers.ProtoDump
Console.Error.WriteLine("including assembly e.g. ProjectNamespace.Message,Company.Project");
return 1;
}
- IMessage defaultMessage;
- try
+ Type type = Type.GetType(args[0]);
+ if (type == null)
{
- defaultMessage = MessageUtil.GetDefaultMessage(args[0]);
- }
- catch (ArgumentException e)
- {
- Console.Error.WriteLine(e.Message);
+ Console.Error.WriteLine("Unable to load type {0}.", args[0]);
return 1;
}
- try
+ if (!typeof(IMessage).IsAssignableFrom(type))
{
- IBuilder builder = defaultMessage.WeakCreateBuilderForType();
- if (builder == null)
- {
- Console.Error.WriteLine("Unable to create builder");
- return 1;
- }
- byte[] inputData = File.ReadAllBytes(args[1]);
- builder.WeakMergeFrom(ByteString.CopyFrom(inputData));
- Console.WriteLine(TextFormat.PrintToString(builder.WeakBuild()));
- return 0;
+ Console.Error.WriteLine("Type {0} doesn't implement IMessage.", args[0]);
+ return 1;
}
- catch (Exception e)
+ IMessage message = (IMessage) Activator.CreateInstance(type);
+ using (var input = File.OpenRead(args[1]))
{
- Console.Error.WriteLine("Error: {0}", e.Message);
- Console.Error.WriteLine();
- Console.Error.WriteLine("Detailed exception information: {0}", e);
- return 1;
+ message.MergeFrom(input);
}
+ Console.WriteLine(message);
+ return 0;
}
}
} \ No newline at end of file