Skip to content

Commit

Permalink
Merge remote branch 'craig/typedcollections' into typedcollections
Browse files Browse the repository at this point in the history
  • Loading branch information
lanwin committed May 24, 2010
2 parents 86fe919 + f452be7 commit b2c7bfb
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 25 deletions.
2 changes: 1 addition & 1 deletion source/MongoDB.Tests/UnitTests/TestOid.cs
Expand Up @@ -136,7 +136,7 @@ public void TestNotEquals()
}

[Test]
[ExpectedException(typeof(ArgumentNullException))]
[ExpectedException(typeof(ArgumentException))]
public void TestNullValue()
{
new Oid(String.Empty);
Expand Down
Expand Up @@ -74,7 +74,7 @@ public AutoMappingProfile()
{
_conventions = new ConventionProfile();
_isSubClass = t => false;
_memberFinder = PublicOrProtectedMemberFinder.Instance;
_memberFinder = DefaultMemberFinder.Instance;
}

/// <summary>
Expand Down
Expand Up @@ -7,16 +7,16 @@ namespace MongoDB.Configuration.Mapping.Auto
/// <summary>
///
/// </summary>
public class PublicOrProtectedMemberFinder : IMemberFinder
public class DefaultMemberFinder : IMemberFinder
{
///<summary>
///</summary>
public static readonly PublicOrProtectedMemberFinder Instance = new PublicOrProtectedMemberFinder();
public static readonly DefaultMemberFinder Instance = new DefaultMemberFinder();

/// <summary>
/// Initializes a new instance of the <see cref="PublicOrProtectedMemberFinder"/> class.
/// Initializes a new instance of the <see cref="DefaultMemberFinder"/> class.
/// </summary>
private PublicOrProtectedMemberFinder()
private DefaultMemberFinder()
{
}

Expand All @@ -32,18 +32,18 @@ public IEnumerable<MemberInfo> 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;
}
}
Expand Down
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
Expand Down Expand Up @@ -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<Action<object, object>> lambda = Expression.Lambda<Action<object, object>>(
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<object, object>)method.CreateDelegate(typeof(Action<object, object>));
var result = lambda.Compile();
setterCache[key] = result;
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion 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;
Expand Down
2 changes: 1 addition & 1 deletion source/MongoDB/MongoDB.csproj
Expand Up @@ -231,7 +231,7 @@
<Compile Include="Configuration\Mapping\Auto\IAutoMappingProfile.cs" />
<Compile Include="Configuration\Mapping\Auto\IMemberFinder.cs" />
<Compile Include="Configuration\Mapping\Auto\MemberOverrides.cs" />
<Compile Include="Configuration\Mapping\Auto\PublicOrProtectedMemberFinder.cs" />
<Compile Include="Configuration\Mapping\Auto\DefaultMemberFinder.cs" />
<Compile Include="Configuration\Mapping\Conventions\ConventionProfile.cs" />
<Compile Include="Configuration\Mapping\Conventions\DefaultCollectionAdapterConvention.cs" />
<Compile Include="Configuration\Mapping\Conventions\DefaultDefaultValueConvention.cs" />
Expand Down

0 comments on commit b2c7bfb

Please sign in to comment.