GeoJsonGeometryCollection.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.Serialization.Attributes;
  20. using MongoDB.Driver.GeoJsonObjectModel.Serializers;
  21. namespace MongoDB.Driver.GeoJsonObjectModel
  22. {
  23. /// <summary>
  24. /// Represents a GeoJson GeometryCollection object.
  25. /// </summary>
  26. /// <typeparam name="TCoordinates">The type of the coordinates.</typeparam>
  27. [BsonSerializer(typeof(GeoJsonGeometryCollectionSerializer<>))]
  28. public class GeoJsonGeometryCollection<TCoordinates> : GeoJsonGeometry<TCoordinates> where TCoordinates : GeoJsonCoordinates
  29. {
  30. // private fields
  31. private ReadOnlyCollection<GeoJsonGeometry<TCoordinates>> _geometries;
  32. // constructors
  33. /// <summary>
  34. /// Initializes a new instance of the <see cref="GeoJsonGeometryCollection{TCoordinates}"/> class.
  35. /// </summary>
  36. /// <param name="geometries">The geometries.</param>
  37. public GeoJsonGeometryCollection(IEnumerable<GeoJsonGeometry<TCoordinates>> geometries)
  38. : this(null, geometries)
  39. {
  40. }
  41. /// <summary>
  42. /// Initializes a new instance of the <see cref="GeoJsonGeometryCollection{TCoordinates}"/> class.
  43. /// </summary>
  44. /// <param name="args">The additional args.</param>
  45. /// <param name="geometries">The geometries.</param>
  46. public GeoJsonGeometryCollection(GeoJsonObjectArgs<TCoordinates> args, IEnumerable<GeoJsonGeometry<TCoordinates>> geometries)
  47. : base(args)
  48. {
  49. if (geometries == null)
  50. {
  51. throw new ArgumentNullException("geometries");
  52. }
  53. var geometriesArray = geometries.ToArray();
  54. if (geometriesArray.Contains(null))
  55. {
  56. throw new ArgumentException("One of the geometries is null.", "geometries");
  57. }
  58. _geometries = new ReadOnlyCollection<GeoJsonGeometry<TCoordinates>>(geometriesArray);
  59. }
  60. // public properties
  61. /// <summary>
  62. /// Gets the geometries.
  63. /// </summary>
  64. public ReadOnlyCollection<GeoJsonGeometry<TCoordinates>> Geometries
  65. {
  66. get { return _geometries; }
  67. }
  68. /// <summary>
  69. /// Gets the type of the GeoJson object.
  70. /// </summary>
  71. public override GeoJsonObjectType Type
  72. {
  73. get { return GeoJsonObjectType.GeometryCollection; }
  74. }
  75. }
  76. }