예제 #1
0
        protected override Object Call(DynamicPropertyDescriptor descriptor, Object underlying)
        {
            try
            {
                if (descriptor.HasParameters)
                {
                    return(descriptor.Method.Invoke(underlying, _paramList));
                }

                var array = (Array)descriptor.Method.Invoke(underlying, null);
                if (array == null)
                {
                    return(null);
                }
                if (array.Length <= _index)
                {
                    return(null);
                }
                return(array.GetValue(_index));
            }
            catch (InvalidCastException e)
            {
                throw PropertyUtility.GetMismatchException(descriptor.Method.Target, underlying, e);
            }
            catch (PropertyAccessException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new PropertyAccessException(e);
            }
        }
예제 #2
0
        public bool IsExistsProperty(EventBean eventBean)
        {
            DynamicPropertyDescriptor desc = GetPopulateCache(eventBean.Underlying);

            if (desc.GetMethod() == null)
            {
                return(false);
            }
            return(true);
        }
예제 #3
0
        public Object Get(EventBean eventBean)
        {
            DynamicPropertyDescriptor desc = GetPopulateCache(eventBean.Underlying);

            if (desc.GetMethod() == null)
            {
                return(null);
            }
            return(Call(desc, eventBean.Underlying));
        }
예제 #4
0
        public bool IsBeanExistsProperty(Object @object)
        {
            DynamicPropertyDescriptor desc = GetPopulateCache(@object);

            if (desc.GetMethod() == null)
            {
                return(false);
            }
            return(true);
        }
예제 #5
0
        public Object GetBeanProp(Object @object)
        {
            DynamicPropertyDescriptor desc = GetPopulateCache(@object);

            if (desc.GetMethod() == null)
            {
                return(null);
            }
            return(Call(desc, @object));
        }
예제 #6
0
        protected override Object Call(DynamicPropertyDescriptor descriptor, Object underlying)
        {
            try
            {
                if (descriptor.HasParameters)
                {
                    return(descriptor.GetMethod().Invoke(underlying, _paramList));
                }

                var result = descriptor.GetMethod().Invoke(underlying, null);
                if (result == null)
                {
                    return(null);
                }

                if (result is DataMap)
                {
                    var resultDictionary = (DataMap)result;
                    return(resultDictionary.Get(_paramList[0]));
                }

                Func <object, DataMap> resultFactory = null;

                var resultType = result.GetType();
                if (ReferenceEquals(resultType, _lastResultType))
                {
                    resultFactory = _lastResultFactory;
                }
                else
                {
                    _lastResultFactory = resultFactory = MagicMarker.GetStringDictionaryFactory(resultType);
                    _lastResultType    = resultType;
                }

                if (resultFactory != null)
                {
                    var resultDictionary = resultFactory.Invoke(result);
                    return(resultDictionary.Get(_paramList[0]));
                }

                return(null);
            }
            catch (InvalidCastException e)
            {
                throw PropertyUtility.GetMismatchException(descriptor.GetMethod().Target, underlying, e);
            }
            catch (PropertyAccessException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new PropertyAccessException(e);
            }
        }
예제 #7
0
        private DynamicPropertyDescriptor GetPopulateCache(Object obj)
        {
            // Check if the method is already there
            Type target = obj.GetType();

            foreach (DynamicPropertyDescriptor desc in _cache)
            {
                if (desc.GetClazz() == target)
                {
                    return(desc);
                }
            }

            // need to add it
            using (_iLock.Acquire())
            {
                foreach (DynamicPropertyDescriptor desc in _cache)
                {
                    if (desc.GetClazz() == target)
                    {
                        return(desc);
                    }
                }

                // Lookup method to use
                MethodInfo method = DetermineMethod(target);

                // Cache descriptor and create fast method
                DynamicPropertyDescriptor propertyDescriptor;
                if (method == null)
                {
                    propertyDescriptor = new DynamicPropertyDescriptor(target, null, false);
                }
                else
                {
                    FastClass  fastClass  = FastClass.Create(target);
                    FastMethod fastMethod = fastClass.GetMethod(method);
                    propertyDescriptor = new DynamicPropertyDescriptor(target, fastMethod, fastMethod.ParameterCount > 0);
                }
                _cache.Add(propertyDescriptor);
                return(propertyDescriptor);
            }
        }
예제 #8
0
 protected override Object Call(DynamicPropertyDescriptor descriptor, Object underlying)
 {
     try
     {
         return(descriptor.GetMethod().Invoke(underlying, null));
     }
     catch (InvalidCastException e)
     {
         throw PropertyUtility.GetMismatchException(descriptor.GetMethod().Target, underlying, e);
     }
     catch (PropertyAccessException)
     {
         throw;
     }
     catch (Exception e)
     {
         throw new PropertyAccessException(e);
     }
 }
        private static DynamicPropertyDescriptor GetPopulateCache(CopyOnWriteList <DynamicPropertyDescriptor> cache, DynamicPropertyGetterBase dynamicPropertyGetterBase, Object obj, EventAdapterService eventAdapterService)
        {
            // Check if the method is already there
            var target = obj.GetType();

            foreach (DynamicPropertyDescriptor desc in cache)
            {
                if (desc.Clazz == target)
                {
                    return(desc);
                }
            }

            // need to add it
            lock (dynamicPropertyGetterBase)
            {
                foreach (DynamicPropertyDescriptor desc in cache)
                {
                    if (desc.Clazz == target)
                    {
                        return(desc);
                    }
                }

                // Lookup method to use
                var method = dynamicPropertyGetterBase.DetermineMethod(target);

                // Cache descriptor and create fast method
                DynamicPropertyDescriptor propertyDescriptor;
                if (method == null)
                {
                    propertyDescriptor = new DynamicPropertyDescriptor(target, null, false);
                }
                else
                {
                    var fastClass  = FastClass.Create(target);
                    var fastMethod = fastClass.GetMethod(method);
                    propertyDescriptor = new DynamicPropertyDescriptor(target, fastMethod, fastMethod.ParameterCount > 0);
                }
                cache.Add(propertyDescriptor);
                return(propertyDescriptor);
            }
        }
예제 #10
0
 /// <summary>
 /// Call the getter to obtains the return result object, or null if no such method
 /// exists.
 /// </summary>
 /// <param name="descriptor">provides method information for the class</param>
 /// <param name="underlying">is the underlying object to ask for the property value</param>
 /// <returns>
 /// underlying
 /// </returns>
 protected abstract Object Call(DynamicPropertyDescriptor descriptor, Object underlying);