diff options
author | Jon Skeet <skeet@pobox.com> | 2008-10-22 13:30:34 +0100 |
---|---|---|
committer | Jon Skeet <skeet@pobox.com> | 2008-10-22 13:30:34 +0100 |
commit | 6803686bc06c4d96afd9bd2637f7b37a58596699 (patch) | |
tree | 4b21c563f4cd4e399fbc0b253bc2f15e822eae88 /src/ProtoGen/SourceGeneratorBase.cs | |
parent | f0589506c96600dcd01319b9d1929d87505f3daa (diff) | |
download | protobuf-6803686bc06c4d96afd9bd2637f7b37a58596699.tar.gz protobuf-6803686bc06c4d96afd9bd2637f7b37a58596699.tar.bz2 protobuf-6803686bc06c4d96afd9bd2637f7b37a58596699.zip |
First cut at new layout
Diffstat (limited to 'src/ProtoGen/SourceGeneratorBase.cs')
-rw-r--r-- | src/ProtoGen/SourceGeneratorBase.cs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/ProtoGen/SourceGeneratorBase.cs b/src/ProtoGen/SourceGeneratorBase.cs new file mode 100644 index 00000000..563c64a1 --- /dev/null +++ b/src/ProtoGen/SourceGeneratorBase.cs @@ -0,0 +1,50 @@ +using System.Collections.Generic; +using Google.ProtocolBuffers.DescriptorProtos; +using Google.ProtocolBuffers.Descriptors; + +namespace Google.ProtocolBuffers.ProtoGen { + internal abstract class SourceGeneratorBase<T> where T : IDescriptor { + + private readonly T descriptor; + + protected SourceGeneratorBase(T descriptor) { + this.descriptor = descriptor; + } + + protected T Descriptor { + get { return descriptor; } + } + + protected string ClassAccessLevel { + get { + // Default to public + return !descriptor.File.Options.HasExtension(CSharpOptions.CSharpPublicClasses) + || descriptor.File.Options.GetExtension(CSharpOptions.CSharpPublicClasses) ? "public" : "internal"; + } + } + + public bool MultipleFiles { + get { return descriptor.File.Options.GetExtension(CSharpOptions.CSharpMultipleFiles); } + } + + protected static void WriteChildren<TChild>(TextGenerator writer, string region, IEnumerable<TChild> children) + where TChild : IDescriptor { + // Copy the set of children; makes access easier + List<TChild> copy = new List<TChild>(children); + if (copy.Count == 0) { + return; + } + + if (region != null) { + writer.WriteLine("#region {0}", region); + } + foreach (TChild child in children) { + SourceGenerators.CreateGenerator(child).Generate(writer); + } + if (region != null) { + writer.WriteLine("#endregion"); + writer.WriteLine(); + } + } + } +} |