diff --git a/source/MongoDB.Tests/UnitTests/TestOid.cs b/source/MongoDB.Tests/UnitTests/TestOid.cs index 6df593f7..768068a9 100644 --- a/source/MongoDB.Tests/UnitTests/TestOid.cs +++ b/source/MongoDB.Tests/UnitTests/TestOid.cs @@ -136,7 +136,7 @@ public void TestNotEquals() } [Test] - [ExpectedException(typeof(ArgumentNullException))] + [ExpectedException(typeof(ArgumentException))] public void TestNullValue() { new Oid(String.Empty); diff --git a/source/MongoDB/Configuration/Mapping/Auto/AutoMappingProfile.cs b/source/MongoDB/Configuration/Mapping/Auto/AutoMappingProfile.cs index cab3536e..135456df 100644 --- a/source/MongoDB/Configuration/Mapping/Auto/AutoMappingProfile.cs +++ b/source/MongoDB/Configuration/Mapping/Auto/AutoMappingProfile.cs @@ -74,7 +74,7 @@ public AutoMappingProfile() { _conventions = new ConventionProfile(); _isSubClass = t => false; - _memberFinder = PublicOrProtectedMemberFinder.Instance; + _memberFinder = DefaultMemberFinder.Instance; } /// diff --git a/source/MongoDB/Configuration/Mapping/Auto/PublicOrProtectedMemberFinder.cs b/source/MongoDB/Configuration/Mapping/Auto/DefaultMemberFinder.cs similarity index 61% rename from source/MongoDB/Configuration/Mapping/Auto/PublicOrProtectedMemberFinder.cs rename to source/MongoDB/Configuration/Mapping/Auto/DefaultMemberFinder.cs index 706bf682..bd59e419 100644 --- a/source/MongoDB/Configuration/Mapping/Auto/PublicOrProtectedMemberFinder.cs +++ b/source/MongoDB/Configuration/Mapping/Auto/DefaultMemberFinder.cs @@ -7,16 +7,16 @@ namespace MongoDB.Configuration.Mapping.Auto /// /// /// - public class PublicOrProtectedMemberFinder : IMemberFinder + public class DefaultMemberFinder : IMemberFinder { /// /// - public static readonly PublicOrProtectedMemberFinder Instance = new PublicOrProtectedMemberFinder(); + public static readonly DefaultMemberFinder Instance = new DefaultMemberFinder(); /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - private PublicOrProtectedMemberFinder() + private DefaultMemberFinder() { } @@ -32,18 +32,18 @@ public IEnumerable FindMembers(Type type) var getMethod = prop.GetGetMethod(true); var setMethod = prop.GetSetMethod(true); - if(getMethod==null||setMethod==null) + if(getMethod==null || getMethod.IsPrivate || setMethod==null) continue; - if(getMethod.IsPrivate||setMethod.IsPrivate) + if (setMethod.GetParameters().Length != 1) //an indexer continue; yield return prop; } - foreach (var field in type.GetFields()) + foreach (var field in type.GetFields()) //all public fields { - if (!field.IsInitOnly && !field.IsLiteral) + if (!field.IsInitOnly && !field.IsLiteral) //readonly yield return field; } } diff --git a/source/MongoDB/Configuration/Mapping/Model/MemberReflectionOptimizer.cs b/source/MongoDB/Configuration/Mapping/Model/MemberReflectionOptimizer.cs index f58bc601..c69bb35e 100644 --- a/source/MongoDB/Configuration/Mapping/Model/MemberReflectionOptimizer.cs +++ b/source/MongoDB/Configuration/Mapping/Model/MemberReflectionOptimizer.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Reflection; @@ -165,20 +165,18 @@ public static class MemberReflectionOptimizer if (!propertyInfo.CanWrite) throw new InvalidOperationException("Cannot create a setter for a readonly property."); - var method = new DynamicMethod("Set" + propertyInfo.Name, null, new[] { typeof(object), typeof(object) }, true); - var gen = method.GetILGenerator(); + ParameterExpression instanceParameter = Expression.Parameter(typeof(object), "target"); + ParameterExpression valueParameter = Expression.Parameter(typeof(object), "value"); - var sourceType = propertyInfo.DeclaringType; - var setter = propertyInfo.GetSetMethod(true); + Expression> lambda = Expression.Lambda>( + Expression.Call( + Expression.Convert(instanceParameter, propertyInfo.DeclaringType), + propertyInfo.GetSetMethod(true), + Expression.Convert(valueParameter, propertyInfo.PropertyType)), + instanceParameter, + valueParameter); - gen.Emit(OpCodes.Ldarg_0); - gen.Emit(OpCodes.Castclass, sourceType); - gen.Emit(OpCodes.Ldarg_1); - gen.Emit(OpCodes.Unbox_Any, propertyInfo.PropertyType); - gen.Emit(OpCodes.Callvirt, setter); - gen.Emit(OpCodes.Ret); - - var result = (Action)method.CreateDelegate(typeof(Action)); + var result = lambda.Compile(); setterCache[key] = result; return result; } diff --git a/source/MongoDB/Linq/Translators/ProjectionBuilder.cs b/source/MongoDB/Linq/Translators/ProjectionBuilder.cs index 13f65c34..347f94ad 100644 --- a/source/MongoDB/Linq/Translators/ProjectionBuilder.cs +++ b/source/MongoDB/Linq/Translators/ProjectionBuilder.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; diff --git a/source/MongoDB/MongoDB.csproj b/source/MongoDB/MongoDB.csproj index cc0f8eab..b3ec788e 100644 --- a/source/MongoDB/MongoDB.csproj +++ b/source/MongoDB/MongoDB.csproj @@ -231,7 +231,7 @@ - +