/* 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.Collections.Generic;
using System.Collections.ObjectModel;
namespace MongoDB.Bson.Serialization.Serializers
{
///
/// Represents a serializer for readonly collection.
///
/// The type of the item.
public class ReadOnlyCollectionSerializer :
EnumerableInterfaceImplementerSerializerBase, TItem>
{
// constructors
///
/// Initializes a new instance of the class.
///
public ReadOnlyCollectionSerializer()
{
}
///
/// Initializes a new instance of the class.
///
/// The item serializer.
public ReadOnlyCollectionSerializer(IBsonSerializer itemSerializer)
: base(itemSerializer)
{
}
///
/// Initializes a new instance of the class.
///
/// The serializer registry.
public ReadOnlyCollectionSerializer(IBsonSerializerRegistry serializerRegistry)
: base(serializerRegistry)
{
}
// public methods
///
/// Returns a serializer that has been reconfigured with the specified item serializer.
///
/// The item serializer.
/// The reconfigured serializer.
public ReadOnlyCollectionSerializer WithItemSerializer(IBsonSerializer itemSerializer)
{
return new ReadOnlyCollectionSerializer(itemSerializer);
}
// protected methods
///
/// Creates the accumulator.
///
/// The accumulator.
protected override object CreateAccumulator()
{
return new List();
}
///
/// Finalizes the result.
///
/// The accumulator.
/// The final result.
protected override ReadOnlyCollection FinalizeResult(object accumulator)
{
return ((List)accumulator).AsReadOnly();
}
}
}