diff options
author | csharptest <roger@csharptest.net> | 2012-10-14 11:55:10 -0500 |
---|---|---|
committer | rogerk <devnull@localhost> | 2012-10-14 11:55:10 -0500 |
commit | 14e011f61ba2f5976f287e67f4ad82e0cdc546cd (patch) | |
tree | 4cd4d2056f763261af13161e72d0845c9b530b5f /src/ProtoGen | |
parent | 7d53c1291202b1b503fb611829514e17fdef053b (diff) | |
download | protobuf-14e011f61ba2f5976f287e67f4ad82e0cdc546cd.tar.gz protobuf-14e011f61ba2f5976f287e67f4ad82e0cdc546cd.tar.bz2 protobuf-14e011f61ba2f5976f287e67f4ad82e0cdc546cd.zip |
Add generated_code_attributes option, defaulted to false to generate the CompilerGeneratedAttribute and GeneratedCodeAttribute attributes
Diffstat (limited to 'src/ProtoGen')
-rw-r--r-- | src/ProtoGen/EnumGenerator.cs | 4 | ||||
-rw-r--r-- | src/ProtoGen/MessageGenerator.cs | 12 | ||||
-rw-r--r-- | src/ProtoGen/ServiceGenerator.cs | 8 | ||||
-rw-r--r-- | src/ProtoGen/ServiceInterfaceGenerator.cs | 16 | ||||
-rw-r--r-- | src/ProtoGen/SourceGeneratorBase.cs | 10 | ||||
-rw-r--r-- | src/ProtoGen/UmbrellaClassGenerator.cs | 4 |
6 files changed, 21 insertions, 33 deletions
diff --git a/src/ProtoGen/EnumGenerator.cs b/src/ProtoGen/EnumGenerator.cs index 35fda7ed..a6ed45d1 100644 --- a/src/ProtoGen/EnumGenerator.cs +++ b/src/ProtoGen/EnumGenerator.cs @@ -47,9 +47,7 @@ namespace Google.ProtocolBuffers.ProtoGen // TODO(jonskeet): Write out enum descriptors? Can be retrieved from file...
public void Generate(TextGenerator writer)
{
- writer.WriteLine("[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]");
- writer.WriteLine("[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"{0}\", \"{1}\")]",
- GetType().Assembly.GetName().Name, GetType().Assembly.GetName().Version);
+ WriteGeneratedCodeAttributes(writer);
writer.WriteLine("{0} enum {1} {{", ClassAccessLevel, Descriptor.Name);
writer.Indent();
foreach (EnumValueDescriptor value in Descriptor.Values)
diff --git a/src/ProtoGen/MessageGenerator.cs b/src/ProtoGen/MessageGenerator.cs index 9529ff13..fb43f3c9 100644 --- a/src/ProtoGen/MessageGenerator.cs +++ b/src/ProtoGen/MessageGenerator.cs @@ -173,9 +173,7 @@ namespace Google.ProtocolBuffers.ProtoGen writer.WriteLine("[global::System.SerializableAttribute()]");
}
writer.WriteLine("[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]");
- writer.WriteLine("[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]");
- writer.WriteLine("[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"{0}\", \"{1}\")]",
- GetType().Assembly.GetName().Name, GetType().Assembly.GetName().Version);
+ WriteGeneratedCodeAttributes(writer);
writer.WriteLine("{0} sealed partial class {1} : pb::{2}Message{3}<{1}, {1}.Builder> {{",
ClassAccessLevel, ClassName,
Descriptor.Proto.ExtensionRangeCount > 0 ? "Extendable" : "Generated",
@@ -239,9 +237,7 @@ namespace Google.ProtocolBuffers.ProtoGen {
writer.WriteLine("#region Nested types");
writer.WriteLine("[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]");
- writer.WriteLine("[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]");
- writer.WriteLine("[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"{0}\", \"{1}\")]",
- GetType().Assembly.GetName().Name, GetType().Assembly.GetName().Version);
+ WriteGeneratedCodeAttributes(writer);
writer.WriteLine("public static partial class Types {");
writer.Indent();
WriteChildren(writer, null, Descriptor.EnumTypes);
@@ -578,9 +574,7 @@ namespace Google.ProtocolBuffers.ProtoGen writer.WriteLine("[global::System.SerializableAttribute()]");
}
writer.WriteLine("[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]");
- writer.WriteLine("[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]");
- writer.WriteLine("[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"{0}\", \"{1}\")]",
- GetType().Assembly.GetName().Name, GetType().Assembly.GetName().Version);
+ WriteGeneratedCodeAttributes(writer);
writer.WriteLine("{0} sealed partial class Builder : pb::{2}Builder{3}<{1}, Builder> {{",
ClassAccessLevel, ClassName,
Descriptor.Proto.ExtensionRangeCount > 0 ? "Extendable" : "Generated", RuntimeSuffix);
diff --git a/src/ProtoGen/ServiceGenerator.cs b/src/ProtoGen/ServiceGenerator.cs index ac84d3d8..a6b9eb28 100644 --- a/src/ProtoGen/ServiceGenerator.cs +++ b/src/ProtoGen/ServiceGenerator.cs @@ -54,9 +54,7 @@ namespace Google.ProtocolBuffers.ProtoGen public void Generate(TextGenerator writer)
{
writer.WriteLine("[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]");
- writer.WriteLine("[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]");
- writer.WriteLine("[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"{0}\", \"{1}\")]",
- GetType().Assembly.GetName().Name, GetType().Assembly.GetName().Version);
+ WriteGeneratedCodeAttributes(writer);
writer.WriteLine("{0} abstract class {1} : pb::IService {{", ClassAccessLevel, Descriptor.Name);
writer.Indent();
@@ -156,9 +154,7 @@ namespace Google.ProtocolBuffers.ProtoGen writer.WriteLine("}");
writer.WriteLine();
writer.WriteLine("[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]");
- writer.WriteLine("[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]");
- writer.WriteLine("[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"{0}\", \"{1}\")]",
- GetType().Assembly.GetName().Name, GetType().Assembly.GetName().Version);
+ WriteGeneratedCodeAttributes(writer);
writer.WriteLine("{0} class Stub : {1} {{", ClassAccessLevel, GetClassName(Descriptor));
writer.Indent();
writer.WriteLine("internal Stub(pb::IRpcChannel channel) {");
diff --git a/src/ProtoGen/ServiceInterfaceGenerator.cs b/src/ProtoGen/ServiceInterfaceGenerator.cs index 64b6d69b..11e3d3d0 100644 --- a/src/ProtoGen/ServiceInterfaceGenerator.cs +++ b/src/ProtoGen/ServiceInterfaceGenerator.cs @@ -104,9 +104,7 @@ namespace Google.ProtocolBuffers.ProtoGen writer.WriteLine("[global::System.Runtime.InteropServices.GuidAttribute(\"{0}\")]",
new Guid(options.InterfaceId));
}
- writer.WriteLine("[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]");
- writer.WriteLine("[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"{0}\", \"{1}\")]",
- GetType().Assembly.GetName().Name, GetType().Assembly.GetName().Version);
+ WriteGeneratedCodeAttributes(writer);
writer.WriteLine("{0} partial interface I{1} {{", ClassAccessLevel, Descriptor.Name);
writer.Indent();
@@ -147,9 +145,7 @@ namespace Google.ProtocolBuffers.ProtoGen writer.WriteLine("[global::System.CLSCompliant(false)]");
}
writer.WriteLine("[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]");
- writer.WriteLine("[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]");
- writer.WriteLine("[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"{0}\", \"{1}\")]",
- GetType().Assembly.GetName().Name, GetType().Assembly.GetName().Version);
+ WriteGeneratedCodeAttributes(writer);
writer.WriteLine("{0} partial class {1} : I{1}, pb::IRpcDispatch, global::System.IDisposable {{",
ClassAccessLevel, Descriptor.Name);
writer.Indent();
@@ -196,9 +192,7 @@ namespace Google.ProtocolBuffers.ProtoGen writer.WriteLine("[global::System.CLSCompliant(false)]");
}
writer.WriteLine("[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]");
- writer.WriteLine("[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]");
- writer.WriteLine("[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"{0}\", \"{1}\")]",
- GetType().Assembly.GetName().Name, GetType().Assembly.GetName().Version);
+ WriteGeneratedCodeAttributes(writer);
writer.WriteLine("public partial class Dispatch : pb::IRpcDispatch, global::System.IDisposable {");
writer.Indent();
writer.WriteLine("private readonly bool dispose;");
@@ -248,9 +242,7 @@ namespace Google.ProtocolBuffers.ProtoGen writer.WriteLine("[global::System.CLSCompliant(false)]");
}
writer.WriteLine("[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]");
- writer.WriteLine("[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]");
- writer.WriteLine("[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"{0}\", \"{1}\")]",
- GetType().Assembly.GetName().Name, GetType().Assembly.GetName().Version);
+ WriteGeneratedCodeAttributes(writer);
writer.WriteLine(
"public partial class ServerStub : pb::IRpcServerStub, global::System.IDisposable {");
writer.Indent();
diff --git a/src/ProtoGen/SourceGeneratorBase.cs b/src/ProtoGen/SourceGeneratorBase.cs index fd833373..535c6f73 100644 --- a/src/ProtoGen/SourceGeneratorBase.cs +++ b/src/ProtoGen/SourceGeneratorBase.cs @@ -129,6 +129,16 @@ namespace Google.ProtocolBuffers.ProtoGen get { return descriptor.File.CSharpOptions.PublicClasses ? "public" : "internal"; }
}
+ protected void WriteGeneratedCodeAttributes(TextGenerator writer)
+ {
+ if (descriptor.File.CSharpOptions.GeneratedCodeAttributes)
+ {
+ writer.WriteLine("[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]");
+ writer.WriteLine("[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"{0}\", \"{1}\")]",
+ GetType().Assembly.GetName().Name, GetType().Assembly.GetName().Version);
+ }
+ }
+
protected void WriteChildren<TChild>(TextGenerator writer, string region, IEnumerable<TChild> children)
where TChild : IDescriptor
{
diff --git a/src/ProtoGen/UmbrellaClassGenerator.cs b/src/ProtoGen/UmbrellaClassGenerator.cs index 85dd4606..ef41be5d 100644 --- a/src/ProtoGen/UmbrellaClassGenerator.cs +++ b/src/ProtoGen/UmbrellaClassGenerator.cs @@ -167,9 +167,7 @@ namespace Google.ProtocolBuffers.ProtoGen writer.WriteLine("[global::System.Diagnostics.Contracts.ContractVerificationAttribute(false)]");
}
writer.WriteLine("[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]");
- writer.WriteLine("[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]");
- writer.WriteLine("[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"{0}\", \"{1}\")]",
- GetType().Assembly.GetName().Name, GetType().Assembly.GetName().Version);
+ WriteGeneratedCodeAttributes(writer);
writer.WriteLine("{0} static partial class {1} {{", ClassAccessLevel,
Descriptor.CSharpOptions.UmbrellaClassname);
writer.WriteLine();
|