Commit 752d1a37 authored by csharptest's avatar csharptest Committed by rogerk

Added option generate_private_ctor to disable private ctor generation

parent 4a6ed749
...@@ -42,6 +42,9 @@ message CSharpFileOptions { ...@@ -42,6 +42,9 @@ message CSharpFileOptions {
// Generate messages/builders with the [Serializable] attribute // Generate messages/builders with the [Serializable] attribute
optional bool add_serializable = 9 [default = false]; optional bool add_serializable = 9 [default = false];
// Generates a private ctor for Message types
optional bool generate_private_ctor = 10 [default = true];
// The extension that should be appended to the umbrella_classname when creating files. // The extension that should be appended to the umbrella_classname when creating files.
optional string file_extension = 221 [default = ".cs"]; optional string file_extension = 221 [default = ".cs"];
......
...@@ -181,8 +181,11 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -181,8 +181,11 @@ namespace Google.ProtocolBuffers.ProtoGen
Descriptor.Proto.ExtensionRangeCount > 0 ? "Extendable" : "Generated", Descriptor.Proto.ExtensionRangeCount > 0 ? "Extendable" : "Generated",
RuntimeSuffix); RuntimeSuffix);
writer.Indent(); writer.Indent();
if (Descriptor.File.CSharpOptions.GeneratePrivateCtor)
{
writer.WriteLine("private {0}() {{ }}", ClassName); writer.WriteLine("private {0}() {{ }}", ClassName);
// Must call BuildPartial() to make sure all lists are made read-only }
// Must call MakeReadOnly() to make sure all lists are made read-only
writer.WriteLine("private static readonly {0} defaultInstance = new {0}().MakeReadOnly();", ClassName); writer.WriteLine("private static readonly {0} defaultInstance = new {0}().MakeReadOnly();", ClassName);
if (OptimizeSpeed) if (OptimizeSpeed)
......
...@@ -52,37 +52,37 @@ namespace Google.ProtocolBuffers.DescriptorProtos { ...@@ -52,37 +52,37 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
byte[] descriptorData = global::System.Convert.FromBase64String( byte[] descriptorData = global::System.Convert.FromBase64String(
"CiRnb29nbGUvcHJvdG9idWYvY3NoYXJwX29wdGlvbnMucHJvdG8SD2dvb2ds" + "CiRnb29nbGUvcHJvdG9idWYvY3NoYXJwX29wdGlvbnMucHJvdG8SD2dvb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0aW9ucw=="); "6AcgASgLMiQuZ29vZ2xlLnByb3RvYnVmLkNTaGFycE1ldGhvZE9wdGlvbnM=");
pbd::FileDescriptor.InternalDescriptorAssigner assigner = delegate(pbd::FileDescriptor root) { pbd::FileDescriptor.InternalDescriptorAssigner assigner = delegate(pbd::FileDescriptor root) {
descriptor = root; descriptor = root;
internal__static_google_protobuf_CSharpFileOptions__Descriptor = Descriptor.MessageTypes[0]; internal__static_google_protobuf_CSharpFileOptions__Descriptor = Descriptor.MessageTypes[0];
internal__static_google_protobuf_CSharpFileOptions__FieldAccessorTable = internal__static_google_protobuf_CSharpFileOptions__FieldAccessorTable =
new pb::FieldAccess.FieldAccessorTable<global::Google.ProtocolBuffers.DescriptorProtos.CSharpFileOptions, global::Google.ProtocolBuffers.DescriptorProtos.CSharpFileOptions.Builder>(internal__static_google_protobuf_CSharpFileOptions__Descriptor, new pb::FieldAccess.FieldAccessorTable<global::Google.ProtocolBuffers.DescriptorProtos.CSharpFileOptions, global::Google.ProtocolBuffers.DescriptorProtos.CSharpFileOptions.Builder>(internal__static_google_protobuf_CSharpFileOptions__Descriptor,
new string[] { "Namespace", "UmbrellaClassname", "PublicClasses", "MultipleFiles", "NestClasses", "CodeContracts", "ExpandNamespaceDirectories", "ClsCompliance", "AddSerializable", "FileExtension", "UmbrellaNamespace", "OutputDirectory", "IgnoreGoogleProtobuf", "ServiceGeneratorType", }); new string[] { "Namespace", "UmbrellaClassname", "PublicClasses", "MultipleFiles", "NestClasses", "CodeContracts", "ExpandNamespaceDirectories", "ClsCompliance", "AddSerializable", "GeneratePrivateCtor", "FileExtension", "UmbrellaNamespace", "OutputDirectory", "IgnoreGoogleProtobuf", "ServiceGeneratorType", });
internal__static_google_protobuf_CSharpFieldOptions__Descriptor = Descriptor.MessageTypes[1]; internal__static_google_protobuf_CSharpFieldOptions__Descriptor = Descriptor.MessageTypes[1];
internal__static_google_protobuf_CSharpFieldOptions__FieldAccessorTable = internal__static_google_protobuf_CSharpFieldOptions__FieldAccessorTable =
new pb::FieldAccess.FieldAccessorTable<global::Google.ProtocolBuffers.DescriptorProtos.CSharpFieldOptions, global::Google.ProtocolBuffers.DescriptorProtos.CSharpFieldOptions.Builder>(internal__static_google_protobuf_CSharpFieldOptions__Descriptor, new pb::FieldAccess.FieldAccessorTable<global::Google.ProtocolBuffers.DescriptorProtos.CSharpFieldOptions, global::Google.ProtocolBuffers.DescriptorProtos.CSharpFieldOptions.Builder>(internal__static_google_protobuf_CSharpFieldOptions__Descriptor,
...@@ -128,8 +128,8 @@ namespace Google.ProtocolBuffers.DescriptorProtos { ...@@ -128,8 +128,8 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
public sealed partial class CSharpFileOptions : pb::GeneratedMessage<CSharpFileOptions, CSharpFileOptions.Builder> { public sealed partial class CSharpFileOptions : pb::GeneratedMessage<CSharpFileOptions, CSharpFileOptions.Builder> {
private CSharpFileOptions() { } private CSharpFileOptions() { }
private static readonly CSharpFileOptions defaultInstance = new CSharpFileOptions().MakeReadOnly(); private static readonly CSharpFileOptions defaultInstance = new CSharpFileOptions().MakeReadOnly();
private static readonly string[] _cSharpFileOptionsFieldNames = new string[] { "add_serializable", "cls_compliance", "code_contracts", "expand_namespace_directories", "file_extension", "ignore_google_protobuf", "multiple_files", "namespace", "nest_classes", "output_directory", "public_classes", "service_generator_type", "umbrella_classname", "umbrella_namespace" }; private static readonly string[] _cSharpFileOptionsFieldNames = new string[] { "add_serializable", "cls_compliance", "code_contracts", "expand_namespace_directories", "file_extension", "generate_private_ctor", "ignore_google_protobuf", "multiple_files", "namespace", "nest_classes", "output_directory", "public_classes", "service_generator_type", "umbrella_classname", "umbrella_namespace" };
private static readonly uint[] _cSharpFileOptionsFieldTags = new uint[] { 72, 64, 48, 56, 1770, 1792, 32, 10, 40, 1786, 24, 1800, 18, 1778 }; private static readonly uint[] _cSharpFileOptionsFieldTags = new uint[] { 72, 64, 48, 56, 1770, 80, 1792, 32, 10, 40, 1786, 24, 1800, 18, 1778 };
public static CSharpFileOptions DefaultInstance { public static CSharpFileOptions DefaultInstance {
get { return defaultInstance; } get { return defaultInstance; }
} }
...@@ -240,6 +240,16 @@ namespace Google.ProtocolBuffers.DescriptorProtos { ...@@ -240,6 +240,16 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
get { return addSerializable_; } get { return addSerializable_; }
} }
public const int GeneratePrivateCtorFieldNumber = 10;
private bool hasGeneratePrivateCtor;
private bool generatePrivateCtor_ = true;
public bool HasGeneratePrivateCtor {
get { return hasGeneratePrivateCtor; }
}
public bool GeneratePrivateCtor {
get { return generatePrivateCtor_; }
}
public const int FileExtensionFieldNumber = 221; public const int FileExtensionFieldNumber = 221;
private bool hasFileExtension; private bool hasFileExtension;
private string fileExtension_ = ".cs"; private string fileExtension_ = ".cs";
...@@ -300,19 +310,19 @@ namespace Google.ProtocolBuffers.DescriptorProtos { ...@@ -300,19 +310,19 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
int size = SerializedSize; int size = SerializedSize;
string[] field_names = _cSharpFileOptionsFieldNames; string[] field_names = _cSharpFileOptionsFieldNames;
if (hasNamespace) { if (hasNamespace) {
output.WriteString(1, field_names[7], Namespace); output.WriteString(1, field_names[8], Namespace);
} }
if (hasUmbrellaClassname) { if (hasUmbrellaClassname) {
output.WriteString(2, field_names[12], UmbrellaClassname); output.WriteString(2, field_names[13], UmbrellaClassname);
} }
if (hasPublicClasses) { if (hasPublicClasses) {
output.WriteBool(3, field_names[10], PublicClasses); output.WriteBool(3, field_names[11], PublicClasses);
} }
if (hasMultipleFiles) { if (hasMultipleFiles) {
output.WriteBool(4, field_names[6], MultipleFiles); output.WriteBool(4, field_names[7], MultipleFiles);
} }
if (hasNestClasses) { if (hasNestClasses) {
output.WriteBool(5, field_names[8], NestClasses); output.WriteBool(5, field_names[9], NestClasses);
} }
if (hasCodeContracts) { if (hasCodeContracts) {
output.WriteBool(6, field_names[2], CodeContracts); output.WriteBool(6, field_names[2], CodeContracts);
...@@ -326,20 +336,23 @@ namespace Google.ProtocolBuffers.DescriptorProtos { ...@@ -326,20 +336,23 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (hasAddSerializable) { if (hasAddSerializable) {
output.WriteBool(9, field_names[0], AddSerializable); output.WriteBool(9, field_names[0], AddSerializable);
} }
if (hasGeneratePrivateCtor) {
output.WriteBool(10, field_names[5], GeneratePrivateCtor);
}
if (hasFileExtension) { if (hasFileExtension) {
output.WriteString(221, field_names[4], FileExtension); output.WriteString(221, field_names[4], FileExtension);
} }
if (hasUmbrellaNamespace) { if (hasUmbrellaNamespace) {
output.WriteString(222, field_names[13], UmbrellaNamespace); output.WriteString(222, field_names[14], UmbrellaNamespace);
} }
if (hasOutputDirectory) { if (hasOutputDirectory) {
output.WriteString(223, field_names[9], OutputDirectory); output.WriteString(223, field_names[10], OutputDirectory);
} }
if (hasIgnoreGoogleProtobuf) { if (hasIgnoreGoogleProtobuf) {
output.WriteBool(224, field_names[5], IgnoreGoogleProtobuf); output.WriteBool(224, field_names[6], IgnoreGoogleProtobuf);
} }
if (hasServiceGeneratorType) { if (hasServiceGeneratorType) {
output.WriteEnum(225, field_names[11], (int) ServiceGeneratorType, ServiceGeneratorType); output.WriteEnum(225, field_names[12], (int) ServiceGeneratorType, ServiceGeneratorType);
} }
UnknownFields.WriteTo(output); UnknownFields.WriteTo(output);
} }
...@@ -378,6 +391,9 @@ namespace Google.ProtocolBuffers.DescriptorProtos { ...@@ -378,6 +391,9 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (hasAddSerializable) { if (hasAddSerializable) {
size += pb::CodedOutputStream.ComputeBoolSize(9, AddSerializable); size += pb::CodedOutputStream.ComputeBoolSize(9, AddSerializable);
} }
if (hasGeneratePrivateCtor) {
size += pb::CodedOutputStream.ComputeBoolSize(10, GeneratePrivateCtor);
}
if (hasFileExtension) { if (hasFileExtension) {
size += pb::CodedOutputStream.ComputeStringSize(221, FileExtension); size += pb::CodedOutputStream.ComputeStringSize(221, FileExtension);
} }
...@@ -546,6 +562,9 @@ namespace Google.ProtocolBuffers.DescriptorProtos { ...@@ -546,6 +562,9 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (other.HasAddSerializable) { if (other.HasAddSerializable) {
AddSerializable = other.AddSerializable; AddSerializable = other.AddSerializable;
} }
if (other.HasGeneratePrivateCtor) {
GeneratePrivateCtor = other.GeneratePrivateCtor;
}
if (other.HasFileExtension) { if (other.HasFileExtension) {
FileExtension = other.FileExtension; FileExtension = other.FileExtension;
} }
...@@ -640,6 +659,10 @@ namespace Google.ProtocolBuffers.DescriptorProtos { ...@@ -640,6 +659,10 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
result.hasAddSerializable = input.ReadBool(ref result.addSerializable_); result.hasAddSerializable = input.ReadBool(ref result.addSerializable_);
break; break;
} }
case 80: {
result.hasGeneratePrivateCtor = input.ReadBool(ref result.generatePrivateCtor_);
break;
}
case 1770: { case 1770: {
result.hasFileExtension = input.ReadString(ref result.fileExtension_); result.hasFileExtension = input.ReadString(ref result.fileExtension_);
break; break;
...@@ -860,6 +883,26 @@ namespace Google.ProtocolBuffers.DescriptorProtos { ...@@ -860,6 +883,26 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
return this; return this;
} }
public bool HasGeneratePrivateCtor {
get { return result.hasGeneratePrivateCtor; }
}
public bool GeneratePrivateCtor {
get { return result.GeneratePrivateCtor; }
set { SetGeneratePrivateCtor(value); }
}
public Builder SetGeneratePrivateCtor(bool value) {
PrepareBuilder();
result.hasGeneratePrivateCtor = true;
result.generatePrivateCtor_ = value;
return this;
}
public Builder ClearGeneratePrivateCtor() {
PrepareBuilder();
result.hasGeneratePrivateCtor = false;
result.generatePrivateCtor_ = true;
return this;
}
public bool HasFileExtension { public bool HasFileExtension {
get { return result.hasFileExtension; } get { return result.hasFileExtension; }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment