internal static DynamicMemberHandle GetCachedField(Type objectType, string fieldName) { var key = new MethodCacheKey(objectType.FullName, fieldName, GetParameterTypes(null)); DynamicMemberHandle mh = null; if (!_memberCache.TryGetValue(key, out mh)) { lock (_memberCache) { if (!_memberCache.TryGetValue(key, out mh)) { FieldInfo info = objectType.GetField(fieldName, fieldFlags); if (info == null) { throw new InvalidOperationException( string.Format(Resources.MemberNotFoundException, fieldName)); } mh = new DynamicMemberHandle(info); _memberCache.Add(key, mh); } } } return(mh); }
internal static DynamicMemberHandle GetCachedField(Type objectType, string fieldName) { var key = new MethodCacheKey(objectType.FullName, fieldName, GetParameterTypes(null)); DynamicMemberHandle mh = null; if (!_memberCache.TryGetValue(key, out mh)) { lock (_memberCache) { if (!_memberCache.TryGetValue(key, out mh)) { FieldInfo info = objectType.GetField(fieldName, fieldFlags); if (info == null) throw new InvalidOperationException( string.Format(Resources.MemberNotFoundException, fieldName)); mh = new DynamicMemberHandle(info); _memberCache.Add(key, mh); } } } return mh; }
public MemberMapping(DynamicMemberHandle fromMemberHandle, DynamicMemberHandle toMemberHandle) { FromMemberHandle = fromMemberHandle; ToMemberHandle = toMemberHandle; }
private static void SetValueWithCoercion(object target, DynamicMemberHandle handle, object value) { var oldValue = handle.DynamicMemberGet(target); Type pType = handle.MemberType; if (!pType.IsGenericType || (pType.IsGenericType && pType.GetGenericTypeDefinition() != typeof(Nullable<>))) { if (pType.IsValueType && (pType.IsPrimitive || pType == typeof(decimal)) && value == null) { value = 0; } } if (value != null) { Type vType = Utilities.GetPropertyType(value.GetType()); value = Utilities.CoerceValue(pType, vType, oldValue, value); } handle.DynamicMemberSet(target, value); }