From d3f2d098fa39596bf6ea59bb93d485e8aaaf7476 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Mon, 8 Feb 2010 11:28:57 +0000 Subject: Allow creation of namespace directories --- src/ProtoGen/Generator.cs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/ProtoGen/Generator.cs') 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 { /// 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); + } + /// /// 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. -- cgit v1.2.3