Ejemplo n.º 1
0
 internal static DynamicMemberHandle GetCachedProperty(Type objectType, string propertyName)
 {
     var key = new MethodCacheKey(objectType.FullName, propertyName, GetParameterTypes(null));
     DynamicMemberHandle mh = null;
     if (!_memberCache.TryGetValue(key, out mh))
     {
         lock (_memberCache)
         {
             if (!_memberCache.TryGetValue(key, out mh))
             {
                 PropertyInfo info = objectType.GetProperty(propertyName, propertyFlags);
                 if (info == null)
                     throw new InvalidOperationException(
                       string.Format("Member not found on object ({0})", propertyName));
                 mh = new DynamicMemberHandle(info);
                 _memberCache.Add(key, mh);
             }
         }
     }
     return mh;
 }
Ejemplo 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:{0}", fieldName));
                        }
                        mh = new DynamicMemberHandle(info);
                        _memberCache.Add(key, mh);
                    }
                }
            }
            return(mh);
        }
Ejemplo n.º 3
0
        internal static DynamicMemberHandle GetCachedProperty(Type objectType, string propertyName)
        {
            var key = new MethodCacheKey(objectType.FullName, propertyName, GetParameterTypes(null));
            DynamicMemberHandle mh = null;

            if (!_memberCache.TryGetValue(key, out mh))
            {
                lock (_memberCache)
                {
                    if (!_memberCache.TryGetValue(key, out mh))
                    {
                        PropertyInfo info = objectType.GetProperty(propertyName, propertyFlags);
                        if (info == null)
                        {
                            throw new InvalidOperationException(
                                      string.Format("Member not found on object ({0})", propertyName));
                        }
                        mh = new DynamicMemberHandle(info);
                        _memberCache.Add(key, mh);
                    }
                }
            }
            return(mh);
        }
Ejemplo n.º 4
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:{0}", fieldName));
                 mh = new DynamicMemberHandle(info);
                 _memberCache.Add(key, mh);
             }
         }
     }
     return mh;
 }