JsonReaderSettings.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* Copyright 2010-2014 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 JsonReader.
  20. /// </summary>
  21. [Serializable]
  22. public class JsonReaderSettings : BsonReaderSettings
  23. {
  24. // private static fields
  25. private static JsonReaderSettings __defaults = null; // delay creation to pick up the latest default values
  26. // private fields
  27. private bool _closeInput = false;
  28. // constructors
  29. /// <summary>
  30. /// Initializes a new instance of the JsonReaderSettings class.
  31. /// </summary>
  32. public JsonReaderSettings()
  33. {
  34. }
  35. /// <summary>
  36. /// Initializes a new instance of the JsonReaderSettings class.
  37. /// </summary>
  38. /// <param name="closeInput">Whether to close the input stream when the reader is closed.</param>
  39. /// <param name="guidRepresentation">The representation for Guids.</param>
  40. [Obsolete("Use the no-argument constructor instead and set the properties.")]
  41. public JsonReaderSettings(bool closeInput, GuidRepresentation guidRepresentation)
  42. : base(guidRepresentation)
  43. {
  44. _closeInput = closeInput;
  45. }
  46. // public static properties
  47. /// <summary>
  48. /// Gets or sets the default settings for a JsonReader.
  49. /// </summary>
  50. public static JsonReaderSettings Defaults
  51. {
  52. get
  53. {
  54. if (__defaults == null)
  55. {
  56. __defaults = new JsonReaderSettings();
  57. }
  58. return __defaults;
  59. }
  60. set { __defaults = value; }
  61. }
  62. // public properties
  63. /// <summary>
  64. /// Gets or sets whether to close the input stream when the reader is closed.
  65. /// </summary>
  66. public bool CloseInput
  67. {
  68. get { return _closeInput; }
  69. set
  70. {
  71. if (IsFrozen) { throw new InvalidOperationException("JsonReaderSettings is frozen."); }
  72. _closeInput = value;
  73. }
  74. }
  75. // public methods
  76. /// <summary>
  77. /// Creates a clone of the settings.
  78. /// </summary>
  79. /// <returns>A clone of the settings.</returns>
  80. public new JsonReaderSettings Clone()
  81. {
  82. return (JsonReaderSettings)CloneImplementation();
  83. }
  84. // protected methods
  85. /// <summary>
  86. /// Creates a clone of the settings.
  87. /// </summary>
  88. /// <returns>A clone of the settings.</returns>
  89. protected override BsonReaderSettings CloneImplementation()
  90. {
  91. var clone = new JsonReaderSettings
  92. {
  93. CloseInput = _closeInput,
  94. GuidRepresentation = GuidRepresentation
  95. };
  96. return clone;
  97. }
  98. }
  99. }