diff options
author | Jon Skeet <skeet@pobox.com> | 2010-02-08 11:28:57 +0000 |
---|---|---|
committer | Jon Skeet <skeet@pobox.com> | 2010-02-08 11:28:57 +0000 |
commit | d3f2d098fa39596bf6ea59bb93d485e8aaaf7476 (patch) | |
tree | a66168d24a972b9b75b9df9d7a90ef9b742e2647 /src/ProtoGen/Generator.cs | |
parent | 55a212d38433e71a6343936872c85d48d553e724 (diff) | |
download | protobuf-d3f2d098fa39596bf6ea59bb93d485e8aaaf7476.tar.gz protobuf-d3f2d098fa39596bf6ea59bb93d485e8aaaf7476.tar.bz2 protobuf-d3f2d098fa39596bf6ea59bb93d485e8aaaf7476.zip |
Allow creation of namespace directories
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. |