Navigation Menu

Skip to content

Commit

Permalink
Move IdGenerationException to Exceptions folder.
Browse files Browse the repository at this point in the history
Move section sub elements to sub folder.
Move MomberRefelctionOptimizer to Mapping/Uitl
  • Loading branch information
lanwin committed May 25, 2010
1 parent 0684a22 commit f20579f
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 87 deletions.
@@ -1,6 +1,4 @@
using System;

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

namespace MongoDB.Configuration.IdGenerators
{
Expand All @@ -18,6 +16,7 @@ public class AssignedIdGenerator : IIdGenerator
public object Generate(object entity, IdMap idMap)
{
var id = idMap.GetValue(entity);

if (Equals(id, idMap.UnsavedValue))
throw new IdGenerationException(string.Format("Ids for {0} must be manually assigned before saving.", entity.GetType()));

Expand Down
33 changes: 0 additions & 33 deletions source/MongoDB/Configuration/IdGenerators/IdGenerationException.cs

This file was deleted.

1 change: 1 addition & 0 deletions source/MongoDB/Configuration/Mapping/Auto/AutoMapper.cs
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using MongoDB.Configuration.Mapping.Model;
using MongoDB.Configuration.Mapping.Util;
using MongoDB.Util;

namespace MongoDB.Configuration.Mapping.Auto
Expand Down
35 changes: 13 additions & 22 deletions source/MongoDB/Configuration/Mapping/Model/MemberMapBase.cs
@@ -1,5 +1,4 @@
using System;
using System.Linq;

namespace MongoDB.Configuration.Mapping.Model
{
Expand All @@ -8,8 +7,6 @@ namespace MongoDB.Configuration.Mapping.Model
public class MemberMapBase
{
private readonly Func<object, object> _getter;
private readonly string _memberName;
private readonly Type _memberReturnType;
private readonly Action<object, object> _setter;

/// <summary>
Expand All @@ -25,28 +22,22 @@ protected MemberMapBase(string memberName, Type memberReturnType, Func<object, o
throw new ArgumentNullException("memberReturnType");

_getter = getter;
_memberName = memberName;
_memberReturnType = memberReturnType;
MemberName = memberName;
MemberReturnType = memberReturnType;
_setter = setter;
}

/// <summary>
/// Gets the name of the member.
/// </summary>
/// <value>The name of the member.</value>
public string MemberName
{
get { return _memberName; }
}
public string MemberName { get; private set; }

/// <summary>
/// Gets the type of the member return.
/// </summary>
/// <value>The type of the member return.</value>
public Type MemberReturnType
{
get { return _memberReturnType; }
}
public Type MemberReturnType { get; private set; }

/// <summary>
/// Gets the value.
Expand All @@ -67,29 +58,29 @@ public virtual void SetValue(object instance, object value)
{
var valueType = value != null ? value.GetType() : typeof(object);

if(valueType != _memberReturnType)
if(valueType != MemberReturnType)
try
{
var code = Convert.GetTypeCode(value);

if(_memberReturnType.IsEnum)
value = Enum.ToObject(_memberReturnType, value);
else if(_memberReturnType.IsGenericType &&
_memberReturnType.GetGenericTypeDefinition() == typeof(Nullable<>))
if(MemberReturnType.IsEnum)
value = Enum.ToObject(MemberReturnType, value);
else if(MemberReturnType.IsGenericType &&
MemberReturnType.GetGenericTypeDefinition() == typeof(Nullable<>))
{
if(value!=null)
value = Convert.ChangeType(value, Nullable.GetUnderlyingType(_memberReturnType));
value = Convert.ChangeType(value, Nullable.GetUnderlyingType(MemberReturnType));
}
else if(code != TypeCode.Object)
value = Convert.ChangeType(value, _memberReturnType);
value = Convert.ChangeType(value, MemberReturnType);
}
catch(FormatException exception)
{
throw new MongoException("Can not convert value from " + valueType + " to " + _memberReturnType + " on " + instance.GetType() + "." + _memberName, exception);
throw new MongoException("Can not convert value from " + valueType + " to " + MemberReturnType + " on " + instance.GetType() + "." + MemberName, exception);
}
catch(ArgumentException exception)
{
throw new MongoException("Can not convert value from " + valueType + " to " + _memberReturnType + " on " + instance.GetType() + "." + _memberName, exception);
throw new MongoException("Can not convert value from " + valueType + " to " + MemberReturnType + " on " + instance.GetType() + "." + MemberName, exception);
}

_setter(instance, value);
Expand Down
Expand Up @@ -5,7 +5,7 @@
using System.Reflection.Emit;
using MongoDB.Util;

namespace MongoDB.Configuration.Mapping.Model
namespace MongoDB.Configuration.Mapping.Util
{
/// <summary>
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions source/MongoDB/Configuration/MongoConfigurationSection.cs
@@ -1,6 +1,7 @@
using System;
using System.Configuration;
using System.Linq;
using MongoDB.Configuration.Section;

namespace MongoDB.Configuration
{
Expand Down
@@ -1,7 +1,7 @@
using System;
using System.Configuration;

namespace MongoDB.Configuration
using System;
using System.Configuration;

namespace MongoDB.Configuration.Section
{
/// <summary>
///
Expand Down Expand Up @@ -43,7 +43,7 @@ protected override Object GetElementKey (ConfigurationElement element)
}

/// <summary>
/// Gets or sets the <see cref="MongoDB.Configuration.ConnectionElement"/> at the specified index.
/// Gets or sets the <see cref="ConnectionElement"/> at the specified index.
/// </summary>
/// <value></value>
public ConnectionElement this[int index] {
Expand All @@ -57,7 +57,7 @@ protected override Object GetElementKey (ConfigurationElement element)
}

/// <summary>
/// Gets the <see cref="MongoDB.Configuration.ConnectionElement"/> with the specified name.
/// Gets the <see cref="ConnectionElement"/> with the specified name.
/// </summary>
/// <value></value>
public new ConnectionElement this[string Name] {
Expand Down
@@ -1,7 +1,7 @@
using System;
using System.Configuration;

namespace MongoDB.Configuration
namespace MongoDB.Configuration.Section
{

/// <summary>
Expand Down
17 changes: 17 additions & 0 deletions source/MongoDB/Exceptions/IdGenerationException.cs
@@ -0,0 +1,17 @@
using System;

namespace MongoDB
{
/// <summary>
///
/// </summary>
[Serializable]
public class IdGenerationException : MongoException
{
/// <summary>
/// Initializes a new instance of the <see cref="IdGenerationException"/> class.
/// </summary>
/// <param name="message">The message.</param>
public IdGenerationException(string message) : base(message) { }
}
}
18 changes: 1 addition & 17 deletions source/MongoDB/Exceptions/UnmappedMemberException.cs
Expand Up @@ -6,28 +6,12 @@ namespace MongoDB
///
/// </summary>
[Serializable]
public class UnmappedMemberException : Exception
public class UnmappedMemberException : MongoException
{
/// <summary>
/// Initializes a new instance of the <see cref="UnmappedMemberException"/> class.
/// </summary>
/// <param name="message">The message.</param>
public UnmappedMemberException(string message) : base(message) { }

/// <summary>
/// Initializes a new instance of the <see cref="UnmappedMemberException"/> class.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param>
/// <exception cref="T:System.ArgumentNullException">
/// The <paramref name="info"/> parameter is null.
/// </exception>
/// <exception cref="T:System.Runtime.Serialization.SerializationException">
/// The class name is null or <see cref="P:System.Exception.HResult"/> is zero (0).
/// </exception>
protected UnmappedMemberException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
}
8 changes: 4 additions & 4 deletions source/MongoDB/MongoDB.csproj
Expand Up @@ -219,7 +219,7 @@
<Compile Include="Configuration\CollectionAdapters\ICollectionAdapter.cs" />
<Compile Include="Configuration\IdGenerators\AssignedIdGenerator.cs" />
<Compile Include="Configuration\IdGenerators\GuidCombGenerator.cs" />
<Compile Include="Configuration\IdGenerators\IdGenerationException.cs" />
<Compile Include="Exceptions\IdGenerationException.cs" />
<Compile Include="Configuration\IdGenerators\IIdGenerator.cs" />
<Compile Include="Configuration\IdGenerators\OidGenerator.cs" />
<Compile Include="Configuration\Mapping\AutoMappingStore.cs" />
Expand Down Expand Up @@ -262,7 +262,7 @@
<Compile Include="Configuration\Mapping\Model\IClassMap.cs" />
<Compile Include="Configuration\Mapping\Model\IdMap.cs" />
<Compile Include="Configuration\Mapping\Model\MemberMapBase.cs" />
<Compile Include="Configuration\Mapping\Model\MemberReflectionOptimizer.cs" />
<Compile Include="Configuration\Mapping\Util\MemberReflectionOptimizer.cs" />
<Compile Include="Configuration\Mapping\Model\PersistentMemberMap.cs" />
<Compile Include="Configuration\Mapping\Model\SubClassMap.cs" />
<Compile Include="Connections\RawConnection.cs" />
Expand Down Expand Up @@ -330,8 +330,8 @@
<Compile Include="Util\Inflector.cs" />
<Compile Include="Util\JsonFormatter.cs" />
<Compile Include="Configuration\MongoConfigurationSection.cs" />
<Compile Include="Configuration\ConnectionElement.cs" />
<Compile Include="Configuration\ConnectionCollection.cs" />
<Compile Include="Configuration\Section\ConnectionElement.cs" />
<Compile Include="Configuration\Section\ConnectionCollection.cs" />
<Compile Include="Cursor_1.cs" />
<Compile Include="ICursor_1.cs" />
<Compile Include="IMongoCollection_1.cs" />
Expand Down

0 comments on commit f20579f

Please sign in to comment.