Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
 public MemberMapping(DynamicMemberHandle fromMemberHandle, DynamicMemberHandle toMemberHandle)
 {
     FromMemberHandle = fromMemberHandle;
     ToMemberHandle = toMemberHandle;
 }
Exemplo n.º 4
0
    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);
    }