Skip to content
Browse files

fix tabs and spaces mixup

  • Loading branch information...
1 parent 9df84d1 commit 90eaeb01032e4144656e07e1b44cbe3f1c2e4dc7 @abolibibelot abolibibelot committed Jul 6, 2010
Showing with 86 additions and 86 deletions.
  1. +86 −86 source/MongoDB/Configuration/Mapping/Util/MemberReflectionOptimizer.cs
View
172 source/MongoDB/Configuration/Mapping/Util/MemberReflectionOptimizer.cs
@@ -13,7 +13,7 @@ public static class MemberReflectionOptimizer
{
private static readonly Dictionary<string, Func<object, object>> GetterCache = new Dictionary<string, Func<object, object>>();
private static readonly Dictionary<string, Action<object, object>> SetterCache = new Dictionary<string, Action<object, object>>();
- private static readonly object SyncObject = new object();
+ private static readonly object SyncObject = new object();
/// <summary>
/// Gets the getter.
@@ -48,31 +48,31 @@ public static class MemberReflectionOptimizer
var key = CreateKey(fieldInfo);
- Func<object, object> getter;
- lock (SyncObject)
- {
- if (GetterCache.TryGetValue(key, out getter))
- return getter;
- }
- //We release the lock here, so the relatively time consuming compiling
- //does not imply contention. The price to pay is potential multiple compilations
- //of the same expression...
- var instanceParameter = Expression.Parameter(typeof (object), "target");
-
- var member = Expression.Field(Expression.Convert(instanceParameter, fieldInfo.DeclaringType), fieldInfo);
-
- var lambda = Expression.Lambda<Func<object, object>>(
- Expression.Convert(member, typeof (object)),
- instanceParameter);
-
- getter = lambda.Compile();
-
- lock(SyncObject)
- {
- GetterCache[key] = getter;
- }
-
- return getter;
+ Func<object, object> getter;
+ lock (SyncObject)
+ {
+ if (GetterCache.TryGetValue(key, out getter))
+ return getter;
+ }
+ //We release the lock here, so the relatively time consuming compiling
+ //does not imply contention. The price to pay is potential multiple compilations
+ //of the same expression...
+ var instanceParameter = Expression.Parameter(typeof (object), "target");
+
+ var member = Expression.Field(Expression.Convert(instanceParameter, fieldInfo.DeclaringType), fieldInfo);
+
+ var lambda = Expression.Lambda<Func<object, object>>(
+ Expression.Convert(member, typeof (object)),
+ instanceParameter);
+
+ getter = lambda.Compile();
+
+ lock(SyncObject)
+ {
+ GetterCache[key] = getter;
+ }
+
+ return getter;
}
/// <summary>
@@ -87,15 +87,15 @@ public static class MemberReflectionOptimizer
var key = CreateKey(propertyInfo);
- Func<object, object> getter;
+ Func<object, object> getter;
- lock (SyncObject)
- {
- if (GetterCache.TryGetValue(key, out getter))
- return getter;
- }
+ lock (SyncObject)
+ {
+ if (GetterCache.TryGetValue(key, out getter))
+ return getter;
+ }
- if(!propertyInfo.CanRead)
+ if(!propertyInfo.CanRead)
throw new InvalidOperationException("Cannot create a getter for a writeonly property.");
var instanceParameter = Expression.Parameter(typeof(object), "target");
@@ -108,11 +108,11 @@ public static class MemberReflectionOptimizer
getter = lambda.Compile();
- lock (SyncObject)
- {
- GetterCache[key] = getter;
- }
- return getter;
+ lock (SyncObject)
+ {
+ GetterCache[key] = getter;
+ }
+ return getter;
}
/// <summary>
@@ -148,36 +148,36 @@ public static class MemberReflectionOptimizer
var key = CreateKey(fieldInfo);
- Action<object, object> setter;
+ Action<object, object> setter;
- lock (SyncObject)
- {
- if (SetterCache.TryGetValue(key, out setter))
- return setter;
- }
-
- if (fieldInfo.IsInitOnly || fieldInfo.IsLiteral)
- throw new InvalidOperationException("Cannot create a setter for a readonly field.");
+ lock (SyncObject)
+ {
+ if (SetterCache.TryGetValue(key, out setter))
+ return setter;
+ }
+
+ if (fieldInfo.IsInitOnly || fieldInfo.IsLiteral)
+ throw new InvalidOperationException("Cannot create a setter for a readonly field.");
- var sourceType = fieldInfo.DeclaringType;
- var method = new DynamicMethod("Set" + fieldInfo.Name, null, new[] {typeof (object), typeof (object)}, true);
- var gen = method.GetILGenerator();
+ var sourceType = fieldInfo.DeclaringType;
+ var method = new DynamicMethod("Set" + fieldInfo.Name, null, new[] {typeof (object), typeof (object)}, true);
+ var gen = method.GetILGenerator();
- gen.Emit(OpCodes.Ldarg_0);
- gen.Emit(OpCodes.Castclass, sourceType);
- gen.Emit(OpCodes.Ldarg_1);
- gen.Emit(OpCodes.Unbox_Any, fieldInfo.FieldType);
- gen.Emit(OpCodes.Stfld, fieldInfo);
- gen.Emit(OpCodes.Ret);
+ gen.Emit(OpCodes.Ldarg_0);
+ gen.Emit(OpCodes.Castclass, sourceType);
+ gen.Emit(OpCodes.Ldarg_1);
+ gen.Emit(OpCodes.Unbox_Any, fieldInfo.FieldType);
+ gen.Emit(OpCodes.Stfld, fieldInfo);
+ gen.Emit(OpCodes.Ret);
- setter = (Action<object, object>) method.CreateDelegate(typeof (Action<object, object>));
+ setter = (Action<object, object>) method.CreateDelegate(typeof (Action<object, object>));
- lock (SyncObject)
- {
- SetterCache[key] = setter;
- }
+ lock (SyncObject)
+ {
+ SetterCache[key] = setter;
+ }
- return setter;
+ return setter;
}
/// <summary>
@@ -192,36 +192,36 @@ public static class MemberReflectionOptimizer
var key = CreateKey(propertyInfo);
- Action<object, object> setter;
+ Action<object, object> setter;
- lock (SyncObject)
- {
- if (SetterCache.TryGetValue(key, out setter))
- return setter;
- }
+ lock (SyncObject)
+ {
+ if (SetterCache.TryGetValue(key, out setter))
+ return setter;
+ }
- if (!propertyInfo.CanWrite)
- throw new InvalidOperationException("Cannot create a setter for a readonly property.");
+ if (!propertyInfo.CanWrite)
+ throw new InvalidOperationException("Cannot create a setter for a readonly property.");
- var instanceParameter = Expression.Parameter(typeof (object), "target");
- var valueParameter = Expression.Parameter(typeof (object), "value");
+ var instanceParameter = Expression.Parameter(typeof (object), "target");
+ var valueParameter = Expression.Parameter(typeof (object), "value");
- var lambda = Expression.Lambda<Action<object, object>>(
- Expression.Call(
- Expression.Convert(instanceParameter, propertyInfo.DeclaringType),
- propertyInfo.GetSetMethod(true),
- Expression.Convert(valueParameter, propertyInfo.PropertyType)),
- instanceParameter,
- valueParameter);
+ var lambda = Expression.Lambda<Action<object, object>>(
+ Expression.Call(
+ Expression.Convert(instanceParameter, propertyInfo.DeclaringType),
+ propertyInfo.GetSetMethod(true),
+ Expression.Convert(valueParameter, propertyInfo.PropertyType)),
+ instanceParameter,
+ valueParameter);
- setter = lambda.Compile();
-
- lock (SyncObject)
- {
- SetterCache[key] = setter;
- }
+ setter = lambda.Compile();
+
+ lock (SyncObject)
+ {
+ SetterCache[key] = setter;
+ }
- return setter;
+ return setter;
}
/// <summary>

0 comments on commit 90eaeb0

Please sign in to comment.
Something went wrong with that request. Please try again.