/* Copyright 2010-present MongoDB Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Driver.GeoJsonObjectModel.Serializers;
namespace MongoDB.Driver.GeoJsonObjectModel
{
///
/// Represents a GeoJson GeometryCollection object.
///
/// The type of the coordinates.
[BsonSerializer(typeof(GeoJsonGeometryCollectionSerializer<>))]
public class GeoJsonGeometryCollection : GeoJsonGeometry where TCoordinates : GeoJsonCoordinates
{
// private fields
private ReadOnlyCollection> _geometries;
// constructors
///
/// Initializes a new instance of the class.
///
/// The geometries.
public GeoJsonGeometryCollection(IEnumerable> geometries)
: this(null, geometries)
{
}
///
/// Initializes a new instance of the class.
///
/// The additional args.
/// The geometries.
public GeoJsonGeometryCollection(GeoJsonObjectArgs args, IEnumerable> geometries)
: base(args)
{
if (geometries == null)
{
throw new ArgumentNullException("geometries");
}
var geometriesArray = geometries.ToArray();
if (geometriesArray.Contains(null))
{
throw new ArgumentException("One of the geometries is null.", "geometries");
}
_geometries = new ReadOnlyCollection>(geometriesArray);
}
// public properties
///
/// Gets the geometries.
///
public ReadOnlyCollection> Geometries
{
get { return _geometries; }
}
///
/// Gets the type of the GeoJson object.
///
public override GeoJsonObjectType Type
{
get { return GeoJsonObjectType.GeometryCollection; }
}
}
}