merged issue-22
diff --git a/src/ProtocolBuffers/DescriptorProtos/CSharpOptions.cs b/src/ProtocolBuffers/DescriptorProtos/CSharpOptions.cs
index 76cb1fe..2bebb01 100644
--- a/src/ProtocolBuffers/DescriptorProtos/CSharpOptions.cs
+++ b/src/ProtocolBuffers/DescriptorProtos/CSharpOptions.cs
@@ -433,7 +433,7 @@
     public override Builder ToBuilder() { return CreateBuilder(this); }

     public override Builder CreateBuilderForType() { return new Builder(); }

     public static Builder CreateBuilder(CSharpFileOptions prototype) {

-      return (Builder) new Builder().MergeFrom(prototype);

+      return new Builder(prototype);

     }

     

     [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]

@@ -443,21 +443,48 @@
       protected override Builder ThisBuilder {

         get { return this; }

       }

-      public Builder() {}

+      public Builder() {

+        result = DefaultInstance ?? new CSharpFileOptions();

+        builderIsReadOnly = result == DefaultInstance;

+      }

+      internal Builder(CSharpFileOptions cloneFrom) {

+        result = cloneFrom;

+        builderIsReadOnly = true;

+      }

       

-      CSharpFileOptions result = new CSharpFileOptions();

+      bool builderIsReadOnly;

+      CSharpFileOptions result;

+      

+      private CSharpFileOptions PrepareBuilder() {

+        if (builderIsReadOnly) {

+          CSharpFileOptions original = result;

+          result = new CSharpFileOptions();

+          builderIsReadOnly = false;

+          MergeFrom(original);

+        }

+        return result;

+      }

+      

+      public override bool IsInitialized {

+        get { return result.IsInitialized; }

+      }

       

       protected override CSharpFileOptions MessageBeingBuilt {

-        get { return result; }

+        get { return PrepareBuilder(); }

       }

       

       public override Builder Clear() {

-        result = new CSharpFileOptions();

+        result = DefaultInstance ?? new CSharpFileOptions();

+        builderIsReadOnly = true;

         return this;

       }

       

       public override Builder Clone() {

-        return new Builder().MergeFrom(result);

+        if (builderIsReadOnly) {

+          return new Builder(result);

+        } else {

+          return new Builder().MergeFrom(result);

+        }

       }

       

       public override pbd::MessageDescriptor DescriptorForType {

@@ -469,12 +496,11 @@
       }

       

       public override CSharpFileOptions BuildPartial() {

-        if (result == null) {

-          throw new global::System.InvalidOperationException("build() has already been called on this Builder");

+        if (builderIsReadOnly) {

+          return result;

         }

-        CSharpFileOptions returnMe = result;

-        result = null;

-        return returnMe;

+        builderIsReadOnly = true;

+        return result;

       }

       

       public override Builder MergeFrom(pb::IMessage other) {

@@ -488,6 +514,7 @@
       

       public override Builder MergeFrom(CSharpFileOptions other) {

         if (other == global::Google.ProtocolBuffers.DescriptorProtos.CSharpFileOptions.DefaultInstance) return this;

+        PrepareBuilder();

         if (other.HasNamespace) {

           Namespace = other.Namespace;

         }

@@ -539,6 +566,7 @@
       }

       

       public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {

+        PrepareBuilder();

         pb::UnknownFieldSet.Builder unknownFields = null;

         uint tag;

         string field_name;

@@ -655,11 +683,13 @@
       }

       public Builder SetNamespace(string value) {

         pb::ThrowHelper.ThrowIfNull(value, "value");

+        PrepareBuilder();

         result.hasNamespace = true;

         result.namespace_ = value;

         return this;

       }

       public Builder ClearNamespace() {

+        PrepareBuilder();

         result.hasNamespace = false;

         result.namespace_ = "";

         return this;

@@ -674,11 +704,13 @@
       }

       public Builder SetUmbrellaClassname(string value) {

         pb::ThrowHelper.ThrowIfNull(value, "value");

+        PrepareBuilder();

         result.hasUmbrellaClassname = true;

         result.umbrellaClassname_ = value;

         return this;

       }

       public Builder ClearUmbrellaClassname() {

+        PrepareBuilder();

         result.hasUmbrellaClassname = false;

         result.umbrellaClassname_ = "";

         return this;

@@ -692,11 +724,13 @@
         set { SetPublicClasses(value); }

       }

       public Builder SetPublicClasses(bool value) {

+        PrepareBuilder();

         result.hasPublicClasses = true;

         result.publicClasses_ = value;

         return this;

       }

       public Builder ClearPublicClasses() {

+        PrepareBuilder();

         result.hasPublicClasses = false;

         result.publicClasses_ = true;

         return this;

@@ -710,11 +744,13 @@
         set { SetMultipleFiles(value); }

       }

       public Builder SetMultipleFiles(bool value) {

+        PrepareBuilder();

         result.hasMultipleFiles = true;

         result.multipleFiles_ = value;

         return this;

       }

       public Builder ClearMultipleFiles() {

+        PrepareBuilder();

         result.hasMultipleFiles = false;

         result.multipleFiles_ = false;

         return this;

@@ -728,11 +764,13 @@
         set { SetNestClasses(value); }

       }

       public Builder SetNestClasses(bool value) {

+        PrepareBuilder();

         result.hasNestClasses = true;

         result.nestClasses_ = value;

         return this;

       }

       public Builder ClearNestClasses() {

+        PrepareBuilder();

         result.hasNestClasses = false;

         result.nestClasses_ = false;

         return this;

@@ -746,11 +784,13 @@
         set { SetCodeContracts(value); }

       }

       public Builder SetCodeContracts(bool value) {

+        PrepareBuilder();

         result.hasCodeContracts = true;

         result.codeContracts_ = value;

         return this;

       }

       public Builder ClearCodeContracts() {

+        PrepareBuilder();

         result.hasCodeContracts = false;

         result.codeContracts_ = false;

         return this;

@@ -764,11 +804,13 @@
         set { SetExpandNamespaceDirectories(value); }

       }

       public Builder SetExpandNamespaceDirectories(bool value) {

+        PrepareBuilder();

         result.hasExpandNamespaceDirectories = true;

         result.expandNamespaceDirectories_ = value;

         return this;

       }

       public Builder ClearExpandNamespaceDirectories() {

+        PrepareBuilder();

         result.hasExpandNamespaceDirectories = false;

         result.expandNamespaceDirectories_ = false;

         return this;

@@ -782,11 +824,13 @@
         set { SetClsCompliance(value); }

       }

       public Builder SetClsCompliance(bool value) {

+        PrepareBuilder();

         result.hasClsCompliance = true;

         result.clsCompliance_ = value;

         return this;

       }

       public Builder ClearClsCompliance() {

+        PrepareBuilder();

         result.hasClsCompliance = false;

         result.clsCompliance_ = true;

         return this;

@@ -800,11 +844,13 @@
         set { SetAddSerializable(value); }

       }

       public Builder SetAddSerializable(bool value) {

+        PrepareBuilder();

         result.hasAddSerializable = true;

         result.addSerializable_ = value;

         return this;

       }

       public Builder ClearAddSerializable() {

+        PrepareBuilder();

         result.hasAddSerializable = false;

         result.addSerializable_ = false;

         return this;

@@ -819,11 +865,13 @@
       }

       public Builder SetFileExtension(string value) {

         pb::ThrowHelper.ThrowIfNull(value, "value");

+        PrepareBuilder();

         result.hasFileExtension = true;

         result.fileExtension_ = value;

         return this;

       }

       public Builder ClearFileExtension() {

+        PrepareBuilder();

         result.hasFileExtension = false;

         result.fileExtension_ = ".cs";

         return this;

@@ -838,11 +886,13 @@
       }

       public Builder SetUmbrellaNamespace(string value) {

         pb::ThrowHelper.ThrowIfNull(value, "value");

+        PrepareBuilder();

         result.hasUmbrellaNamespace = true;

         result.umbrellaNamespace_ = value;

         return this;

       }

       public Builder ClearUmbrellaNamespace() {

+        PrepareBuilder();

         result.hasUmbrellaNamespace = false;

         result.umbrellaNamespace_ = "";

         return this;

@@ -857,11 +907,13 @@
       }

       public Builder SetOutputDirectory(string value) {

         pb::ThrowHelper.ThrowIfNull(value, "value");

+        PrepareBuilder();

         result.hasOutputDirectory = true;

         result.outputDirectory_ = value;

         return this;

       }

       public Builder ClearOutputDirectory() {

+        PrepareBuilder();

         result.hasOutputDirectory = false;

         result.outputDirectory_ = ".";

         return this;

@@ -875,11 +927,13 @@
         set { SetIgnoreGoogleProtobuf(value); }

       }

       public Builder SetIgnoreGoogleProtobuf(bool value) {

+        PrepareBuilder();

         result.hasIgnoreGoogleProtobuf = true;

         result.ignoreGoogleProtobuf_ = value;

         return this;

       }

       public Builder ClearIgnoreGoogleProtobuf() {

+        PrepareBuilder();

         result.hasIgnoreGoogleProtobuf = false;

         result.ignoreGoogleProtobuf_ = false;

         return this;

@@ -893,11 +947,13 @@
         set { SetServiceGeneratorType(value); }

       }

       public Builder SetServiceGeneratorType(global::Google.ProtocolBuffers.DescriptorProtos.CSharpServiceType value) {

+        PrepareBuilder();

         result.hasServiceGeneratorType = true;

         result.serviceGeneratorType_ = value;

         return this;

       }

       public Builder ClearServiceGeneratorType() {

+        PrepareBuilder();

         result.hasServiceGeneratorType = false;

         result.serviceGeneratorType_ = global::Google.ProtocolBuffers.DescriptorProtos.CSharpServiceType.NONE;

         return this;

@@ -1011,7 +1067,7 @@
     public override Builder ToBuilder() { return CreateBuilder(this); }

     public override Builder CreateBuilderForType() { return new Builder(); }

     public static Builder CreateBuilder(CSharpFieldOptions prototype) {

-      return (Builder) new Builder().MergeFrom(prototype);

+      return new Builder(prototype);

     }

     

     [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]

@@ -1021,21 +1077,48 @@
       protected override Builder ThisBuilder {

         get { return this; }

       }

-      public Builder() {}

+      public Builder() {

+        result = DefaultInstance ?? new CSharpFieldOptions();

+        builderIsReadOnly = result == DefaultInstance;

+      }

+      internal Builder(CSharpFieldOptions cloneFrom) {

+        result = cloneFrom;

+        builderIsReadOnly = true;

+      }

       

-      CSharpFieldOptions result = new CSharpFieldOptions();

+      bool builderIsReadOnly;

+      CSharpFieldOptions result;

+      

+      private CSharpFieldOptions PrepareBuilder() {

+        if (builderIsReadOnly) {

+          CSharpFieldOptions original = result;

+          result = new CSharpFieldOptions();

+          builderIsReadOnly = false;

+          MergeFrom(original);

+        }

+        return result;

+      }

+      

+      public override bool IsInitialized {

+        get { return result.IsInitialized; }

+      }

       

       protected override CSharpFieldOptions MessageBeingBuilt {

-        get { return result; }

+        get { return PrepareBuilder(); }

       }

       

       public override Builder Clear() {

-        result = new CSharpFieldOptions();

+        result = DefaultInstance ?? new CSharpFieldOptions();

+        builderIsReadOnly = true;

         return this;

       }

       

       public override Builder Clone() {

-        return new Builder().MergeFrom(result);

+        if (builderIsReadOnly) {

+          return new Builder(result);

+        } else {

+          return new Builder().MergeFrom(result);

+        }

       }

       

       public override pbd::MessageDescriptor DescriptorForType {

@@ -1047,12 +1130,11 @@
       }

       

       public override CSharpFieldOptions BuildPartial() {

-        if (result == null) {

-          throw new global::System.InvalidOperationException("build() has already been called on this Builder");

+        if (builderIsReadOnly) {

+          return result;

         }

-        CSharpFieldOptions returnMe = result;

-        result = null;

-        return returnMe;

+        builderIsReadOnly = true;

+        return result;

       }

       

       public override Builder MergeFrom(pb::IMessage other) {

@@ -1066,6 +1148,7 @@
       

       public override Builder MergeFrom(CSharpFieldOptions other) {

         if (other == global::Google.ProtocolBuffers.DescriptorProtos.CSharpFieldOptions.DefaultInstance) return this;

+        PrepareBuilder();

         if (other.HasPropertyName) {

           PropertyName = other.PropertyName;

         }

@@ -1078,6 +1161,7 @@
       }

       

       public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {

+        PrepareBuilder();

         pb::UnknownFieldSet.Builder unknownFields = null;

         uint tag;

         string field_name;

@@ -1134,11 +1218,13 @@
       }

       public Builder SetPropertyName(string value) {

         pb::ThrowHelper.ThrowIfNull(value, "value");

+        PrepareBuilder();

         result.hasPropertyName = true;

         result.propertyName_ = value;

         return this;

       }

       public Builder ClearPropertyName() {

+        PrepareBuilder();

         result.hasPropertyName = false;

         result.propertyName_ = "";

         return this;

@@ -1252,7 +1338,7 @@
     public override Builder ToBuilder() { return CreateBuilder(this); }

     public override Builder CreateBuilderForType() { return new Builder(); }

     public static Builder CreateBuilder(CSharpServiceOptions prototype) {

-      return (Builder) new Builder().MergeFrom(prototype);

+      return new Builder(prototype);

     }

     

     [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]

@@ -1262,21 +1348,48 @@
       protected override Builder ThisBuilder {

         get { return this; }

       }

-      public Builder() {}

+      public Builder() {

+        result = DefaultInstance ?? new CSharpServiceOptions();

+        builderIsReadOnly = result == DefaultInstance;

+      }

+      internal Builder(CSharpServiceOptions cloneFrom) {

+        result = cloneFrom;

+        builderIsReadOnly = true;

+      }

       

-      CSharpServiceOptions result = new CSharpServiceOptions();

+      bool builderIsReadOnly;

+      CSharpServiceOptions result;

+      

+      private CSharpServiceOptions PrepareBuilder() {

+        if (builderIsReadOnly) {

+          CSharpServiceOptions original = result;

+          result = new CSharpServiceOptions();

+          builderIsReadOnly = false;

+          MergeFrom(original);

+        }

+        return result;

+      }

+      

+      public override bool IsInitialized {

+        get { return result.IsInitialized; }

+      }

       

       protected override CSharpServiceOptions MessageBeingBuilt {

-        get { return result; }

+        get { return PrepareBuilder(); }

       }

       

       public override Builder Clear() {

-        result = new CSharpServiceOptions();

+        result = DefaultInstance ?? new CSharpServiceOptions();

+        builderIsReadOnly = true;

         return this;

       }

       

       public override Builder Clone() {

-        return new Builder().MergeFrom(result);

+        if (builderIsReadOnly) {

+          return new Builder(result);

+        } else {

+          return new Builder().MergeFrom(result);

+        }

       }

       

       public override pbd::MessageDescriptor DescriptorForType {

@@ -1288,12 +1401,11 @@
       }

       

       public override CSharpServiceOptions BuildPartial() {

-        if (result == null) {

-          throw new global::System.InvalidOperationException("build() has already been called on this Builder");

+        if (builderIsReadOnly) {

+          return result;

         }

-        CSharpServiceOptions returnMe = result;

-        result = null;

-        return returnMe;

+        builderIsReadOnly = true;

+        return result;

       }

       

       public override Builder MergeFrom(pb::IMessage other) {

@@ -1307,6 +1419,7 @@
       

       public override Builder MergeFrom(CSharpServiceOptions other) {

         if (other == global::Google.ProtocolBuffers.DescriptorProtos.CSharpServiceOptions.DefaultInstance) return this;

+        PrepareBuilder();

         if (other.HasInterfaceId) {

           InterfaceId = other.InterfaceId;

         }

@@ -1319,6 +1432,7 @@
       }

       

       public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {

+        PrepareBuilder();

         pb::UnknownFieldSet.Builder unknownFields = null;

         uint tag;

         string field_name;

@@ -1375,11 +1489,13 @@
       }

       public Builder SetInterfaceId(string value) {

         pb::ThrowHelper.ThrowIfNull(value, "value");

+        PrepareBuilder();

         result.hasInterfaceId = true;

         result.interfaceId_ = value;

         return this;

       }

       public Builder ClearInterfaceId() {

+        PrepareBuilder();

         result.hasInterfaceId = false;

         result.interfaceId_ = "";

         return this;

@@ -1493,7 +1609,7 @@
     public override Builder ToBuilder() { return CreateBuilder(this); }

     public override Builder CreateBuilderForType() { return new Builder(); }

     public static Builder CreateBuilder(CSharpMethodOptions prototype) {

-      return (Builder) new Builder().MergeFrom(prototype);

+      return new Builder(prototype);

     }

     

     [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]

@@ -1503,21 +1619,48 @@
       protected override Builder ThisBuilder {

         get { return this; }

       }

-      public Builder() {}

+      public Builder() {

+        result = DefaultInstance ?? new CSharpMethodOptions();

+        builderIsReadOnly = result == DefaultInstance;

+      }

+      internal Builder(CSharpMethodOptions cloneFrom) {

+        result = cloneFrom;

+        builderIsReadOnly = true;

+      }

       

-      CSharpMethodOptions result = new CSharpMethodOptions();

+      bool builderIsReadOnly;

+      CSharpMethodOptions result;

+      

+      private CSharpMethodOptions PrepareBuilder() {

+        if (builderIsReadOnly) {

+          CSharpMethodOptions original = result;

+          result = new CSharpMethodOptions();

+          builderIsReadOnly = false;

+          MergeFrom(original);

+        }

+        return result;

+      }

+      

+      public override bool IsInitialized {

+        get { return result.IsInitialized; }

+      }

       

       protected override CSharpMethodOptions MessageBeingBuilt {

-        get { return result; }

+        get { return PrepareBuilder(); }

       }

       

       public override Builder Clear() {

-        result = new CSharpMethodOptions();

+        result = DefaultInstance ?? new CSharpMethodOptions();

+        builderIsReadOnly = true;

         return this;

       }

       

       public override Builder Clone() {

-        return new Builder().MergeFrom(result);

+        if (builderIsReadOnly) {

+          return new Builder(result);

+        } else {

+          return new Builder().MergeFrom(result);

+        }

       }

       

       public override pbd::MessageDescriptor DescriptorForType {

@@ -1529,12 +1672,11 @@
       }

       

       public override CSharpMethodOptions BuildPartial() {

-        if (result == null) {

-          throw new global::System.InvalidOperationException("build() has already been called on this Builder");

+        if (builderIsReadOnly) {

+          return result;

         }

-        CSharpMethodOptions returnMe = result;

-        result = null;

-        return returnMe;

+        builderIsReadOnly = true;

+        return result;

       }

       

       public override Builder MergeFrom(pb::IMessage other) {

@@ -1548,6 +1690,7 @@
       

       public override Builder MergeFrom(CSharpMethodOptions other) {

         if (other == global::Google.ProtocolBuffers.DescriptorProtos.CSharpMethodOptions.DefaultInstance) return this;

+        PrepareBuilder();

         if (other.HasDispatchId) {

           DispatchId = other.DispatchId;

         }

@@ -1560,6 +1703,7 @@
       }

       

       public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {

+        PrepareBuilder();

         pb::UnknownFieldSet.Builder unknownFields = null;

         uint tag;

         string field_name;

@@ -1615,11 +1759,13 @@
         set { SetDispatchId(value); }

       }

       public Builder SetDispatchId(int value) {

+        PrepareBuilder();

         result.hasDispatchId = true;

         result.dispatchId_ = value;

         return this;

       }

       public Builder ClearDispatchId() {

+        PrepareBuilder();

         result.hasDispatchId = false;

         result.dispatchId_ = 0;

         return this;