示例#1
0
        protected override Object Call(DynamicPropertyDescriptor descriptor, Object underlying)
        {
            try
            {
                if (descriptor.HasParameters)
                {
                    return(descriptor.GetMethod().Invoke(underlying, _paramList));
                }

                var array = (Array)descriptor.GetMethod().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.GetMethod().Target, underlying, e);
            }
            catch (PropertyAccessException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new PropertyAccessException(e);
            }
        }
示例#2
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);
            }
        }
        public bool IsExistsProperty(EventBean eventBean)
        {
            DynamicPropertyDescriptor desc = GetPopulateCache(eventBean.Underlying);

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

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

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

            if (desc.GetMethod() == null)
            {
                return(null);
            }
            return(Call(desc, @object));
        }
 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);
     }
 }