示例#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);
        }
示例#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;
 }
示例#3
0
 public MemberMapping(DynamicMemberHandle fromMemberHandle, DynamicMemberHandle toMemberHandle)
 {
     FromMemberHandle = fromMemberHandle;
     ToMemberHandle = toMemberHandle;
 }
示例#4
0
文件: DataMapper.cs 项目: Jaans/csla
    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);
    }