DefaultConventionPack.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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.Collections.Generic;
  16. namespace MongoDB.Bson.Serialization.Conventions
  17. {
  18. /// <summary>
  19. /// Convention pack of defaults.
  20. /// </summary>
  21. public class DefaultConventionPack : IConventionPack
  22. {
  23. // private static fields
  24. private static readonly IConventionPack __defaultConventionPack = new DefaultConventionPack();
  25. // private fields
  26. private readonly IEnumerable<IConvention> _conventions;
  27. // constructors
  28. /// <summary>
  29. /// Initializes a new instance of the <see cref="DefaultConventionPack" /> class.
  30. /// </summary>
  31. private DefaultConventionPack()
  32. {
  33. _conventions = new List<IConvention>
  34. {
  35. new ReadWriteMemberFinderConvention(),
  36. new NamedIdMemberConvention(new [] { "Id", "id", "_id" }),
  37. new NamedExtraElementsMemberConvention(new [] { "ExtraElements" }),
  38. new IgnoreExtraElementsConvention(false),
  39. new ImmutableTypeClassMapConvention(),
  40. new NamedParameterCreatorMapConvention(),
  41. new StringObjectIdIdGeneratorConvention(), // should be before LookupIdGeneratorConvention
  42. new LookupIdGeneratorConvention()
  43. };
  44. }
  45. // public static properties
  46. /// <summary>
  47. /// Gets the instance.
  48. /// </summary>
  49. public static IConventionPack Instance
  50. {
  51. get { return __defaultConventionPack; }
  52. }
  53. // public properties
  54. /// <summary>
  55. /// Gets the conventions.
  56. /// </summary>
  57. public IEnumerable<IConvention> Conventions
  58. {
  59. get { return _conventions; }
  60. }
  61. }
  62. }