WriteConcernError.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 MongoDB.Bson;
  17. namespace MongoDB.Driver
  18. {
  19. /// <summary>
  20. /// Represents the details of a write concern error.
  21. /// </summary>
  22. #if NET452
  23. [Serializable]
  24. #endif
  25. public class WriteConcernError
  26. {
  27. // private fields
  28. private readonly int _code;
  29. private readonly string _codeName;
  30. private readonly BsonDocument _details;
  31. private readonly string _message;
  32. // constructors
  33. internal WriteConcernError(int code, string codeName, string message, BsonDocument details)
  34. {
  35. _code = code;
  36. _codeName = codeName;
  37. _details = details;
  38. _message = message;
  39. }
  40. // public properties
  41. /// <summary>
  42. /// Gets the error code.
  43. /// </summary>
  44. public int Code
  45. {
  46. get { return _code; }
  47. }
  48. /// <summary>
  49. /// Gets the name of the error code.
  50. /// </summary>
  51. /// <value>
  52. /// The name of the error code.
  53. /// </value>
  54. public string CodeName
  55. {
  56. get { return _codeName; }
  57. }
  58. /// <summary>
  59. /// Gets the error information.
  60. /// </summary>
  61. public BsonDocument Details
  62. {
  63. get { return _details; }
  64. }
  65. /// <summary>
  66. /// Gets the error message.
  67. /// </summary>
  68. public string Message
  69. {
  70. get { return _message; }
  71. }
  72. // internal static methods
  73. internal static WriteConcernError FromCore(Core.Operations.BulkWriteConcernError error)
  74. {
  75. return error == null ? null : new WriteConcernError(error.Code, error.CodeName, error.Message, error.Details);
  76. }
  77. }
  78. }