CreateIndexModel.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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.Linq;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. using MongoDB.Driver.Core.Misc;
  21. using MongoDB.Driver.Core.Operations;
  22. namespace MongoDB.Driver
  23. {
  24. /// <summary>
  25. /// Model for creating an index.
  26. /// </summary>
  27. /// <typeparam name="TDocument">The type of the document.</typeparam>
  28. public sealed class CreateIndexModel<TDocument>
  29. {
  30. private readonly IndexKeysDefinition<TDocument> _keys;
  31. private readonly CreateIndexOptions<TDocument> _options;
  32. /// <summary>
  33. /// Initializes a new instance of the <see cref="CreateIndexModel{TDocument}"/> class.
  34. /// </summary>
  35. /// <param name="keys">The keys.</param>
  36. /// <param name="options">The options.</param>
  37. public CreateIndexModel(IndexKeysDefinition<TDocument> keys, CreateIndexOptions options = null)
  38. {
  39. _keys = Ensure.IsNotNull(keys, nameof(keys));
  40. _options = CreateIndexOptions<TDocument>.CoercedFrom(options);
  41. }
  42. /// <summary>
  43. /// Gets the keys.
  44. /// </summary>
  45. public IndexKeysDefinition<TDocument> Keys
  46. {
  47. get { return _keys; }
  48. }
  49. /// <summary>
  50. /// Gets the options.
  51. /// </summary>
  52. public CreateIndexOptions<TDocument> Options
  53. {
  54. get { return _options; }
  55. }
  56. }
  57. }