Skip to content

Commit

Permalink
More minor cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
lanwin committed May 25, 2010
1 parent 5e288db commit 0684a22
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 37 deletions.
53 changes: 30 additions & 23 deletions source/MongoDB/Configuration/Mapping/AutoMappingStore.cs
@@ -1,13 +1,11 @@
using System;
using System.Collections.Generic;

using MongoDB.Configuration.Mapping.Auto;
using MongoDB.Configuration.Mapping.Model;

namespace MongoDB.Configuration.Mapping
{
/// <summary>
///
/// </summary>
public class AutoMappingStore : IMappingStore
{
Expand All @@ -16,65 +14,74 @@ public class AutoMappingStore : IMappingStore
private readonly IMappingStore _wrappedMappingStore;

/// <summary>
/// Initializes a new instance of the <see cref="AutoMappingStore"/> class.
/// Initializes a new instance of the <see cref = "AutoMappingStore" /> class.
/// </summary>
public AutoMappingStore()
: this((IAutoMapper)null, null)
{ }
{
}

/// <summary>
/// Initializes a new instance of the <see cref="AutoMappingStore"/> class.
/// Initializes a new instance of the <see cref = "AutoMappingStore" /> class.
/// </summary>
/// <param name="profile">The profile.</param>
/// <param name = "profile">The profile.</param>
public AutoMappingStore(IAutoMappingProfile profile)
: this(new AutoMapper(profile), null)
{ }
{
}

/// <summary>
/// Initializes a new instance of the <see cref="AutoMappingStore"/> class.
/// Initializes a new instance of the <see cref = "AutoMappingStore" /> class.
/// </summary>
/// <param name="autoMapper">The auto mapper.</param>
/// <param name = "autoMapper">The auto mapper.</param>
public AutoMappingStore(IAutoMapper autoMapper)
: this(autoMapper, null)
{ }
{
}

/// <summary>
/// Initializes a new instance of the <see cref="AutoMappingStore"/> class.
/// Initializes a new instance of the <see cref = "AutoMappingStore" /> class.
/// </summary>
/// <param name="profile">The profile.</param>
/// <param name="mappingStore">The mapping store.</param>
/// <param name = "profile">The profile.</param>
/// <param name = "mappingStore">The mapping store.</param>
public AutoMappingStore(IAutoMappingProfile profile, IMappingStore mappingStore)
: this(new AutoMapper(profile), mappingStore)
{ }
{
}

/// <summary>
/// Initializes a new instance of the <see cref="AutoMappingStore"/> class.
/// Initializes a new instance of the <see cref = "AutoMappingStore" /> class.
/// </summary>
/// <param name="autoMapper">The auto mapper.</param>
/// <param name="mappingStore">The mapping store.</param>
/// <param name = "autoMapper">The auto mapper.</param>
/// <param name = "mappingStore">The mapping store.</param>
public AutoMappingStore(IAutoMapper autoMapper, IMappingStore mappingStore)
{
_autoMapper = autoMapper ?? new AutoMapper();
if(autoMapper == null)
throw new ArgumentNullException("autoMapper");
if(mappingStore == null)
throw new ArgumentNullException("mappingStore");

_autoMapper = autoMapper;
_autoMaps = new Dictionary<Type, IClassMap>();
_wrappedMappingStore = mappingStore;
}

/// <summary>
/// Gets the class map for the specified class type.
/// Gets the class map for the specified class type.
/// </summary>
/// <param name="classType">Type of the entity.</param>
/// <param name = "classType">Type of the entity.</param>
/// <returns></returns>
public IClassMap GetClassMap(Type classType)
{
IClassMap classMap;

if (_autoMaps.TryGetValue(classType, out classMap))
if(_autoMaps.TryGetValue(classType, out classMap))
return classMap;

if (_wrappedMappingStore != null)
if(_wrappedMappingStore != null)
{
classMap = _wrappedMappingStore.GetClassMap(classType);
if (classMap != null)
if(classMap != null)
return classMap;
}

Expand Down
Expand Up @@ -11,16 +11,12 @@ namespace MongoDB.Configuration.Mapping.Model
public class CollectionMemberMap : PersistentMemberMap
{
private readonly ICollectionAdapter _collectionAdapter;
private readonly Type _elementType;

/// <summary>
/// Gets the type of the element.
/// </summary>
/// <value>The type of the element.</value>
public Type ElementType
{
get { return _elementType; }
}
public Type ElementType { get; private set; }

/// <summary>
/// Initializes a new instance of the <see cref="CollectionMemberMap"/> class.
Expand All @@ -37,7 +33,7 @@ public CollectionMemberMap(string memberName, Type memberReturnType, Func<object
: base(memberName, memberReturnType, getter, setter, null, alias, persistNull)
{
_collectionAdapter = collectionAdapter;
_elementType = elementType;
ElementType = elementType;
}

/// <summary>
Expand All @@ -49,6 +45,7 @@ public override object GetValue(object instance)
{
var elements = _collectionAdapter.GetElementsFromCollection(base.GetValue(instance));
var list = new ArrayList();

foreach (var element in elements)
list.Add(element);

Expand All @@ -62,7 +59,7 @@ public override object GetValue(object instance)
/// <param name="value">The value.</param>
public override void SetValue(object instance, object value)
{
base.SetValue(instance, _collectionAdapter.CreateCollection(_elementType, (object[])value));
base.SetValue(instance, _collectionAdapter.CreateCollection(ElementType, (object[])value));
}
}
}
Expand Up @@ -16,6 +16,7 @@ public class ExtendedPropertiesMap : MemberMapBase
/// <param name="setter">The setter.</param>
public ExtendedPropertiesMap(string memberName, Type memberReturnType, Func<object, object> getter, Action<object, object> setter)
: base(memberName, memberReturnType, getter, setter)
{ }
{
}
}
}
8 changes: 2 additions & 6 deletions source/MongoDB/Configuration/Mapping/Model/IdMap.cs
Expand Up @@ -10,16 +10,12 @@ namespace MongoDB.Configuration.Mapping.Model
public sealed class IdMap : PersistentMemberMap
{
private readonly IIdGenerator _generator;
private readonly object _unsavedValue;

/// <summary>
/// Gets the id's unsaved value.
/// </summary>
/// <value>The unsaved value.</value>
public object UnsavedValue
{
get { return _unsavedValue; }
}
public object UnsavedValue { get; private set; }

/// <summary>
/// Initializes a new instance of the <see cref="IdMap"/> class.
Expand All @@ -34,7 +30,7 @@ public IdMap(string memberName, Type memberType, Func<object, object> getter, Ac
: base(memberName, memberType, getter, setter, null, "_id", true)
{
_generator = generator;
_unsavedValue = unsavedValue;
UnsavedValue = unsavedValue;
}

/// <summary>
Expand Down

0 comments on commit 0684a22

Please sign in to comment.