예제 #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);
            }
        }
예제 #3
0
        public bool IsExistsProperty(EventBean eventBean)
        {
            DynamicPropertyDescriptor desc = GetPopulateCache(eventBean.Underlying);

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

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

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

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