diff options
Diffstat (limited to 'src/ProtoGen/Generator.cs')
-rw-r--r-- | src/ProtoGen/Generator.cs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/ProtoGen/Generator.cs b/src/ProtoGen/Generator.cs index 9c0771ee..7e48ad67 100644 --- a/src/ProtoGen/Generator.cs +++ b/src/ProtoGen/Generator.cs @@ -82,12 +82,29 @@ namespace Google.ProtocolBuffers.ProtoGen { /// </summary> private void Generate(FileDescriptor descriptor) { UmbrellaClassGenerator ucg = new UmbrellaClassGenerator(descriptor); - using (TextWriter textWriter = File.CreateText(Path.Combine(options.OutputDirectory, descriptor.CSharpOptions.UmbrellaClassname + ".cs"))) { - TextGenerator writer = new TextGenerator(textWriter); + using (TextWriter textWriter = File.CreateText(GetOutputFile(descriptor))) { + TextGenerator writer = new TextGenerator(textWriter); ucg.Generate(writer); } } + private string GetOutputFile(FileDescriptor descriptor) { + CSharpFileOptions fileOptions = descriptor.CSharpOptions; + string filename = descriptor.CSharpOptions.UmbrellaClassname + ".cs"; + string outputDirectory = options.OutputDirectory; + if (fileOptions.ExpandNamespaceDirectories) { + string package = fileOptions.Namespace; + if (!string.IsNullOrEmpty(package)) { + string[] bits = package.Split('.'); + foreach (string bit in bits) { + outputDirectory = Path.Combine(outputDirectory, bit); + } + Directory.CreateDirectory(outputDirectory); + } + } + return Path.Combine(outputDirectory, filename); + } + /// <summary> /// Resolves any dependencies and converts FileDescriptorProtos into FileDescriptors. /// The list returned is in the same order as the protos are listed in the descriptor set. |