diff options
Diffstat (limited to 'csharp/src/ProtoDump')
-rw-r--r-- | csharp/src/ProtoDump/Program.cs | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/csharp/src/ProtoDump/Program.cs b/csharp/src/ProtoDump/Program.cs index a935e780..d2eee9b7 100644 --- a/csharp/src/ProtoDump/Program.cs +++ b/csharp/src/ProtoDump/Program.cs @@ -36,6 +36,7 @@ using System;
using System.IO;
+using Google.Protobuf;
namespace Google.ProtocolBuffers.ProtoDump
{
@@ -53,36 +54,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 |