BsonDocumentWriterSettings.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Copyright 2010-present MongoDB Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. using System;
  16. namespace MongoDB.Bson.IO
  17. {
  18. /// <summary>
  19. /// Represents settings for a BsonDocumentWriter.
  20. /// </summary>
  21. [Serializable]
  22. public class BsonDocumentWriterSettings : BsonWriterSettings
  23. {
  24. // private static fields
  25. private static BsonDocumentWriterSettings __defaults = null; // delay creation to pick up the latest default values
  26. // constructors
  27. /// <summary>
  28. /// Initializes a new instance of the BsonDocumentWriterSettings class.
  29. /// </summary>
  30. public BsonDocumentWriterSettings()
  31. {
  32. }
  33. /// <summary>
  34. /// Initializes a new instance of the BsonDocumentWriterSettings class.
  35. /// </summary>
  36. /// <param name="guidRepresentation">The representation for Guids.</param>
  37. [Obsolete("Configure serializers instead.")]
  38. public BsonDocumentWriterSettings(GuidRepresentation guidRepresentation)
  39. : base(guidRepresentation)
  40. {
  41. }
  42. // public static properties
  43. /// <summary>
  44. /// Gets or sets the default BsonDocumentWriter settings.
  45. /// </summary>
  46. public static BsonDocumentWriterSettings Defaults
  47. {
  48. get
  49. {
  50. if (__defaults == null)
  51. {
  52. __defaults = new BsonDocumentWriterSettings();
  53. }
  54. return __defaults;
  55. }
  56. set { __defaults = value; }
  57. }
  58. // public methods
  59. /// <summary>
  60. /// Creates a clone of the settings.
  61. /// </summary>
  62. /// <returns>A clone of the settings.</returns>
  63. public new BsonDocumentWriterSettings Clone()
  64. {
  65. return (BsonDocumentWriterSettings)CloneImplementation();
  66. }
  67. // protected methods
  68. /// <summary>
  69. /// Creates a clone of the settings.
  70. /// </summary>
  71. /// <returns>A clone of the settings.</returns>
  72. protected override BsonWriterSettings CloneImplementation()
  73. {
  74. var clone = new BsonDocumentWriterSettings
  75. {
  76. MaxSerializationDepth = MaxSerializationDepth
  77. };
  78. #pragma warning disable 618
  79. if (BsonDefaults.GuidRepresentationMode == GuidRepresentationMode.V2)
  80. {
  81. clone.GuidRepresentation = GuidRepresentation;
  82. }
  83. #pragma warning restore 618
  84. return clone;
  85. }
  86. }
  87. }