BulkWriteUpsert.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. using System.Collections.Generic;
  17. using System.Collections.ObjectModel;
  18. using System.Linq;
  19. using MongoDB.Bson;
  20. using MongoDB.Bson.Serialization.Attributes;
  21. using MongoDB.Driver.Support;
  22. using MongoDB.Shared;
  23. namespace MongoDB.Driver
  24. {
  25. /// <summary>
  26. /// Represents the information about one Upsert.
  27. /// </summary>
  28. #if NET452
  29. [Serializable]
  30. #endif
  31. public class BulkWriteUpsert
  32. {
  33. // private fields
  34. private readonly BsonValue _id;
  35. private readonly int _index;
  36. // constructors
  37. internal BulkWriteUpsert(
  38. int index,
  39. BsonValue id)
  40. {
  41. _index = index;
  42. _id = id;
  43. }
  44. // public properties
  45. /// <summary>
  46. /// Gets the id.
  47. /// </summary>
  48. public BsonValue Id
  49. {
  50. get { return _id; }
  51. }
  52. /// <summary>
  53. /// Gets the index.
  54. /// </summary>
  55. public int Index
  56. {
  57. get { return _index; }
  58. }
  59. // internal static methods
  60. internal static BulkWriteUpsert FromCore(Core.Operations.BulkWriteOperationUpsert upsert)
  61. {
  62. return new BulkWriteUpsert(upsert.Index, upsert.Id);
  63. }
  64. // internal methods
  65. internal BulkWriteUpsert WithMappedIndex(IndexMap indexMap)
  66. {
  67. var mappedIndex = indexMap.Map(_index);
  68. return (_index == mappedIndex) ? this : new BulkWriteUpsert(mappedIndex, _id);
  69. }
  70. }
  71. }