BsonDefaults.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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.Collections.Generic;
  16. using System.Dynamic;
  17. using MongoDB.Bson.Serialization;
  18. namespace MongoDB.Bson
  19. {
  20. /// <summary>
  21. /// A static helper class containing BSON defaults.
  22. /// </summary>
  23. public static class BsonDefaults
  24. {
  25. // private static fields
  26. private static bool __dynamicArraySerializerWasSet;
  27. private static IBsonSerializer __dynamicArraySerializer;
  28. private static bool __dynamicDocumentSerializerWasSet;
  29. private static IBsonSerializer __dynamicDocumentSerializer;
  30. private static GuidRepresentation __guidRepresentation = GuidRepresentation.CSharpLegacy;
  31. private static int __maxDocumentSize = int.MaxValue;
  32. private static int __maxSerializationDepth = 100;
  33. // public static properties
  34. /// <summary>
  35. /// Gets or sets the dynamic array serializer.
  36. /// </summary>
  37. public static IBsonSerializer DynamicArraySerializer
  38. {
  39. get
  40. {
  41. if (!__dynamicArraySerializerWasSet)
  42. {
  43. __dynamicArraySerializer = BsonSerializer.LookupSerializer<List<object>>();
  44. }
  45. return __dynamicArraySerializer;
  46. }
  47. set
  48. {
  49. __dynamicArraySerializerWasSet = true;
  50. __dynamicArraySerializer = value;
  51. }
  52. }
  53. /// <summary>
  54. /// Gets or sets the dynamic document serializer.
  55. /// </summary>
  56. public static IBsonSerializer DynamicDocumentSerializer
  57. {
  58. get
  59. {
  60. if (!__dynamicDocumentSerializerWasSet)
  61. {
  62. __dynamicDocumentSerializer = BsonSerializer.LookupSerializer<ExpandoObject>();
  63. }
  64. return __dynamicDocumentSerializer;
  65. }
  66. set
  67. {
  68. __dynamicDocumentSerializerWasSet = true;
  69. __dynamicDocumentSerializer = value;
  70. }
  71. }
  72. /// <summary>
  73. /// Gets or sets the default representation to be used in serialization of
  74. /// Guids to the database.
  75. /// <seealso cref="MongoDB.Bson.GuidRepresentation"/>
  76. /// </summary>
  77. public static GuidRepresentation GuidRepresentation
  78. {
  79. get { return __guidRepresentation; }
  80. set { __guidRepresentation = value; }
  81. }
  82. /// <summary>
  83. /// Gets or sets the default max document size. The default is 4MiB.
  84. /// </summary>
  85. public static int MaxDocumentSize
  86. {
  87. get { return __maxDocumentSize; }
  88. set { __maxDocumentSize = value; }
  89. }
  90. /// <summary>
  91. /// Gets or sets the default max serialization depth (used to detect circular references during serialization). The default is 100.
  92. /// </summary>
  93. public static int MaxSerializationDepth
  94. {
  95. get { return __maxSerializationDepth; }
  96. set { __maxSerializationDepth = value; }
  97. }
  98. }
  99. }