aboutsummaryrefslogtreecommitdiff
path: root/src/ProtoGen/Generator.cs
diff options
context:
space:
mode:
authorJon Skeet <skeet@pobox.com>2010-02-08 11:28:57 +0000
committerJon Skeet <skeet@pobox.com>2010-02-08 11:28:57 +0000
commitd3f2d098fa39596bf6ea59bb93d485e8aaaf7476 (patch)
treea66168d24a972b9b75b9df9d7a90ef9b742e2647 /src/ProtoGen/Generator.cs
parent55a212d38433e71a6343936872c85d48d553e724 (diff)
downloadprotobuf-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.cs21
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.