private Object GetBeanPropInternal(Object @object, int index)
        {
            try
            {
                String value = (String)_fastMethod.Invoke(@object);
                if (value.Length <= index)
                {
                    return(null);
                }

                return(value[index]);
            }
            catch (InvalidCastException e)
            {
                throw PropertyUtility.GetMismatchException(_fastMethod.Target, @object, e);
            }
            catch (PropertyAccessException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new PropertyAccessException(e);
            }
        }
        public Object GetBeanPropInternal(Object @object, Object key)
        {
            try {
                var result = _fastMethod.Invoke(@object, null);
                if (result == null) {
                    return null;
                }

                if (result is Map) {
                    return ((Map) result).Get(key);
                }

                if (result.GetType().IsGenericDictionary()) {
                    return MagicMarker
                        .GetDictionaryFactory(result.GetType())
                        .Invoke(result)
                        .Get(key);
                }

                return null;
            }
            catch (PropertyAccessException) {
                throw;
            }
            catch (InvalidCastException e) {
                throw PropertyUtility.GetMismatchException(_fastMethod.Target, @object, e);
            }
            catch (TargetInvocationException e) {
                throw PropertyUtility.GetInvocationTargetException(_fastMethod.Target, e);
            }
            catch (Exception e) {
                throw PropertyUtility.GetAccessExceptionMethod(_fastMethod.Target, e);
            }
        }
Example #3
0
        public object GetBeanPropInternal(object @object, int index)
        {
            try
            {
                var value = _method.Invoke(@object, (object[])null).AsObjectList();
                if (value == null)
                {
                    return(null);
                }

                if (value.Count <= index)
                {
                    return(null);
                }

                return(value[index]);
            }
            catch (InvalidCastException e)
            {
                throw PropertyUtility.GetMismatchException(_method, @object, e);
            }
            catch (TargetInvocationException e)
            {
                throw PropertyUtility.GetInvocationTargetException(_method, e);
            }
            catch (ArgumentException e)
            {
                throw new PropertyAccessException(e);
            }
        }
Example #4
0
        /// <summary>
        /// NOTE: Code-generation-invoked method, method name and parameter order matters
        /// </summary>
        /// <param name="descriptor">descriptor</param>
        /// <param name="underlying">target</param>
        /// <param name="key">key</param>
        /// <returns>value</returns>
        public static bool DynamicMappedPropertyExists(
            DynamicPropertyDescriptorByMethod descriptor,
            object underlying,
            string key)
        {
            try {
                if (descriptor.HasParameters)
                {
                    return(true);
                }

                var result = descriptor.Method.Invoke(underlying, null);
                return(result != null && GetMapKeyExistsChecked(result, key));
            }
            catch (InvalidCastException e) {
                throw PropertyUtility.GetMismatchException(descriptor.Method, underlying, e);
            }
            catch (TargetInvocationException e) {
                throw PropertyUtility.GetTargetException(descriptor.Method, e);
            }
            catch (TargetException e) {
                throw PropertyUtility.GetTargetException(descriptor.Method, e);
            }
            catch (ArgumentException e) {
                throw PropertyUtility.GetArgumentException(descriptor.Method, e);
            }
            catch (MemberAccessException e) {
                throw PropertyUtility.GetMemberAccessException(descriptor.Method, e);
            }
        }
Example #5
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);
            }
        }
        /// <summary>
        /// NOTE: Code-generation-invoked method, method name and parameter order matters
        /// </summary>
        /// <param name="descriptor">descriptor</param>
        /// <param name="underlying">target</param>
        /// <param name="index">idx</param>
        /// <returns>null or method</returns>
        public static bool DynamicIndexedPropertyExists(
            DynamicPropertyDescriptorByField descriptor,
            object underlying,
            int index)
        {
            try {
                var array = (Array)descriptor.Field.GetValue(underlying);
                if (array == null)
                {
                    return(false);
                }

                if (array.Length <= index)
                {
                    return(false);
                }

                return(true);
            }
            catch (InvalidCastException e) {
                throw PropertyUtility.GetMismatchException(descriptor.Field, underlying, e);
            }
            catch (ArgumentException e) {
                throw PropertyUtility.GetArgumentException(descriptor.Field, e);
            }
            catch (MemberAccessException e) {
                throw PropertyUtility.GetMemberAccessException(descriptor.Field, e);
            }
        }
Example #7
0
        /// <summary>
        /// NOTE: Code-generation-invoked method, method name and parameter order matters
        /// </summary>
        /// <param name="descriptor">descriptor</param>
        /// <param name="underlying">target</param>
        /// <param name="parameters">params</param>
        /// <returns>value</returns>
        public static object DynamicMappedPropertyGet(
            DynamicPropertyDescriptorByMethod descriptor,
            object underlying,
            object[] parameters)
        {
            try {
                if (descriptor.HasParameters)
                {
                    return(descriptor.Method.Invoke(underlying, parameters));
                }

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

                return(GetMapValueChecked(result, parameters[0]));
            }
            catch (InvalidCastException e) {
                throw PropertyUtility.GetMismatchException(descriptor.Method, underlying, e);
            }
            catch (TargetInvocationException e) {
                throw PropertyUtility.GetTargetException(descriptor.Method, e);
            }
            catch (TargetException e) {
                throw PropertyUtility.GetTargetException(descriptor.Method, e);
            }
            catch (ArgumentException e) {
                throw PropertyUtility.GetArgumentException(descriptor.Method, e);
            }
            catch (MemberAccessException e) {
                throw PropertyUtility.GetMemberAccessException(descriptor.Method, e);
            }
        }
 private object GetBeanPropInternal(object @object, int index)
 {
     try {
         var value = _method.Invoke(@object, null) as Array;
         if (value == null)
             return null;
         if (value.Length <= index)
             return null;
         return value.GetValue(index);
     }
     catch (InvalidCastException e) {
         throw PropertyUtility.GetMismatchException(_method, @object, e);
     }
     catch (TargetInvocationException e) {
         throw PropertyUtility.GetInvocationTargetException(_method, e);
     }
     catch (TargetException e) {
         throw PropertyUtility.GetGenericException(_method, e);
     }
     catch (MemberAccessException e) {
         throw PropertyUtility.GetIllegalAccessException(_method, e);
     }
     catch (ArgumentException e) {
         throw PropertyUtility.GetIllegalArgumentException(_method, e);
     }
 }
        public Object GetBeanPropInternal(Object @object, Object key)
        {
            try {
                var result = _field.GetValue(@object);
                if (result == null) {
                    return null;
                }

                if (result is Map) {
                    return ((Map) result).Get(key);
                }

                var resultType = result.GetType();
                if (resultType.IsGenericDictionary()) {
                    return MagicMarker
                        .GetDictionaryFactory(resultType)
                        .Invoke(result)
                        .Get(key);
                }

                return null;
            }
            catch (PropertyAccessException) {
                throw;
            }
            catch (InvalidCastException e) {
                throw PropertyUtility.GetMismatchException(_field, @object, e);
            }
            catch (ArgumentException e) {
                throw PropertyUtility.GetIllegalArgumentException(_field, e);
            }
            catch (Exception e) {
                throw PropertyUtility.GetAccessExceptionField(_field, e);
            }
        }
        public Object GetBeanPropInternal(Object @object, int index)
        {
            try
            {
                var value = _fastMethod.Invoke(@object, null).AsObjectList();
                if (value == null)
                {
                    return null;
                }

                if (value.Count <= index)
                {
                    return null;
                }
                return value[index];
            }
            catch (InvalidCastException e)
            {
                throw PropertyUtility.GetMismatchException(_fastMethod.Target, @object, e);
            }
            catch (TargetInvocationException e)
            {
                throw PropertyUtility.GetInvocationTargetException(_fastMethod.Target, e);
            }
        }
 public Object GetBeanPropInternal(Object @object, Object key)
 {
     try
     {
         Object result = _method.Invoke(@object, null);
         if (!(result is DataMap))
         {
             return(null);
         }
         DataMap resultMap = (DataMap)result;
         return(resultMap.Get(key));
     }
     catch (InvalidCastException e)
     {
         throw PropertyUtility.GetMismatchException(_method, @object, e);
     }
     catch (TargetInvocationException e)
     {
         throw PropertyUtility.GetInvocationTargetException(_method, e);
     }
     catch (ArgumentException e)
     {
         throw new PropertyAccessException(e);
     }
 }
Example #12
0
        /// <summary>
        /// NOTE: Code-generation-invoked method, method name and parameter order matters
        /// </summary>
        /// <param name="descriptor">descriptor</param>
        /// <param name="underlying">underlying</param>
        /// <param name="ex">exception</param>
        /// <returns>exception</returns>
        public static PropertyAccessException HandleException(
            DynamicPropertyDescriptorByMethod descriptor,
            object underlying,
            Exception ex)
        {
            if (ex is InvalidCastException invalidCastException)
            {
                throw PropertyUtility.GetMismatchException(descriptor.Method, underlying, invalidCastException);
            }

            if (ex is TargetException targetException)
            {
                throw PropertyUtility.GetTargetException(descriptor.Method, targetException);
            }

            if (ex is TargetInvocationException targetInvocationException)
            {
                throw PropertyUtility.GetTargetException(descriptor.Method, targetInvocationException);
            }

            if (ex is ArgumentException argumentException)
            {
                throw PropertyUtility.GetArgumentException(descriptor.Method, argumentException);
            }

            if (ex is MemberAccessException memberAccessException)
            {
                throw PropertyUtility.GetMemberAccessException(descriptor.Method, memberAccessException);
            }

            throw PropertyUtility.GetGeneralException(descriptor.Method, ex);
        }
Example #13
0
        private Object GetBeanPropInternal(Object @object, int index)
        {
            try
            {
                var value = (Array)_method.Invoke(@object, null);
                if (value.Length <= index)
                {
                    return(null);
                }

                return(value.GetValue(index));
            }
            catch (InvalidCastException e)
            {
                throw PropertyUtility.GetMismatchException(_method, @object, e);
            }
            catch (PropertyAccessException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new PropertyAccessException(e);
            }
        }
Example #14
0
        public Object GetBeanPropInternal(Object theObject, int index)
        {
            try
            {
                var value       = _fastMethod.Invoke(theObject, null);
                var valueAsList = value as System.Collections.IList;
                if (valueAsList != null)
                {
                    return(valueAsList.AtIndex(index, i => null));
                }

                return(null);
            }
            catch (InvalidCastException e)
            {
                throw PropertyUtility.GetMismatchException(_fastMethod.Target, theObject, e);
            }
            catch (PropertyAccessException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new PropertyAccessException(e);
            }
        }
Example #15
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 object GetBeanPropInternal(
     object @object,
     int index)
 {
     try {
         var value = _property.GetValue(@object);
         return GetBeanEventIterableValue(value, index);
     }
     catch (InvalidCastException e) {
         throw PropertyUtility.GetMismatchException(_property, @object, e);
     }
 }
Example #17
0
 private object GetBeanPropInternal(
     object @object,
     int index)
 {
     try {
         var value = _method.Invoke(@object, null);
         return GetBeanEventIterableValue(value, index);
     }
     catch (InvalidCastException e) {
         throw PropertyUtility.GetMismatchException(_method, @object, e);
     }
 }
Example #18
0
 public Object GetBeanPropInternal(Object @object, Object key)
 {
     try {
         return _fastMethod.Invoke(@object, new Object[] {key});
     }
     catch (PropertyAccessException) {
         throw;
     }
     catch (InvalidCastException e) {
         throw PropertyUtility.GetMismatchException(_fastMethod.Target, @object, e);
     }
     catch (Exception e) {
         throw PropertyUtility.GetAccessExceptionMethod(_fastMethod.Target, e);
     }
 }
Example #19
0
 public Object GetBeanPropInternal(Object @object, String key)
 {
     try
     {
         var result = _fastMethod.Invoke(@object, null);
         return(GenericExtensions.FetchKeyedValue(result, key, null));
     }
     catch (InvalidCastException e)
     {
         throw PropertyUtility.GetMismatchException(_fastMethod.Target, @object, e);
     }
     catch (TargetInvocationException e)
     {
         throw PropertyUtility.GetInvocationTargetException(_fastMethod.Target, e);
     }
 }
        /// <summary>
        /// NOTE: Code-generation-invoked method, method name and parameter order matters
        /// </summary>
        /// <param name="descriptor">descriptor</param>
        /// <param name="underlying">target</param>
        /// <param name="parameters">params</param>
        /// <param name="index">idx</param>
        /// <returns>null or method</returns>
        public static object DynamicIndexedPropertyGet(
            DynamicPropertyDescriptorByMethod descriptor,
            object underlying,
            object[] parameters,
            int index)
        {
            try {
                if (descriptor.HasParameters)
                {
                    return(descriptor.Method.Invoke(underlying, parameters));
                }

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

                if (result is Array array)
                {
                    return(array.Length > index?array.GetValue(index) : null);
                }

                if (result.GetType().IsGenericList())
                {
                    var list = result.AsObjectList(MagicMarker.SingletonInstance);
                    return(list.Count > index ? list[index] : null);
                }

                return(null);
            }
            catch (InvalidCastException e) {
                throw PropertyUtility.GetMismatchException(descriptor.Method, underlying, e);
            }
            catch (TargetInvocationException e) {
                throw PropertyUtility.GetTargetException(descriptor.Method, e);
            }
            catch (TargetException e) {
                throw PropertyUtility.GetTargetException(descriptor.Method, e);
            }
            catch (ArgumentException e) {
                throw PropertyUtility.GetArgumentException(descriptor.Method, e);
            }
            catch (MemberAccessException e) {
                throw PropertyUtility.GetMemberAccessException(descriptor.Method, e);
            }
        }
 private object GetBeanPropInternal(object @object, int index)
 {
     try
     {
         var value = (Array) _fastMethod.Invoke(@object, null);
         if (value.Length <= index) return null;
         return value.GetValue(index);
     }
     catch (InvalidCastException e)
     {
         throw PropertyUtility.GetMismatchException(_fastMethod.Target, @object, e);
     }
     catch (TargetInvocationException e)
     {
         throw PropertyUtility.GetInvocationTargetException(_fastMethod.Target, e);
     }
 }
Example #22
0
 /// <summary>
 /// NOTE: Code-generation-invoked method, method name and parameter order matters
 /// </summary>
 /// <param name="descriptor">descriptor</param>
 /// <param name="underlying">target</param>
 /// <param name="key">key</param>
 /// <returns>value</returns>
 public static bool DynamicMappedPropertyExists(
     DynamicPropertyDescriptorByField descriptor,
     object underlying,
     string key)
 {
     try {
         var result = descriptor.Field.GetValue(underlying);
         return(GetMapKeyExistsChecked(result, key));
     }
     catch (InvalidCastException e) {
         throw PropertyUtility.GetMismatchException(descriptor.Field, underlying, e);
     }
     catch (ArgumentException e) {
         throw PropertyUtility.GetArgumentException(descriptor.Field, e);
     }
     catch (MemberAccessException e) {
         throw PropertyUtility.GetMemberAccessException(descriptor.Field, e);
     }
 }
Example #23
0
 public static object GetPropertyMap(
     PropertyInfo property,
     object @object,
     object key)
 {
     try {
         var result = property.GetValue(@object);
         return(CollectionUtil.GetMapValueChecked(result, key));
     }
     catch (InvalidCastException e) {
         throw PropertyUtility.GetMismatchException(property, @object, e);
     }
     catch (ArgumentException e) {
         throw PropertyUtility.GetArgumentException(property, e);
     }
     catch (MemberAccessException e) {
         throw PropertyUtility.GetMemberAccessException(property, e);
     }
 }
Example #24
0
 public Object GetBeanProp(Object obj)
 {
     try
     {
         return(_fastMethod.Invoke(obj));
     }
     catch (InvalidCastException e)
     {
         throw PropertyUtility.GetMismatchException(_fastMethod.Target, obj, e);
     }
     catch (PropertyAccessException)
     {
         throw;
     }
     catch (Exception e)
     {
         throw new PropertyAccessException(e);
     }
 }
 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);
     }
 }
Example #26
0
 public override Object Get(EventBean obj)
 {
     try
     {
         return(_fastGetter(obj.Underlying));
     }
     catch (InvalidCastException e)
     {
         throw PropertyUtility.GetMismatchException(_propInfo.GetGetMethod(), obj.Underlying, e);
     }
     catch (PropertyAccessException)
     {
         throw;
     }
     catch (Exception e)
     {
         throw new PropertyAccessException(e);
     }
 }
Example #27
0
 public Object GetBeanProp(Object o)
 {
     try
     {
         Object value = _fastMethod.Invoke(o);
         return(GetEnumerable(value, _index));
     }
     catch (InvalidCastException e)
     {
         throw PropertyUtility.GetMismatchException(_fastMethod.Target, o, e);
     }
     catch (PropertyAccessException)
     {
         throw;
     }
     catch (Exception e)
     {
         throw new PropertyAccessException(e);
     }
 }
Example #28
0
 public Object GetBeanPropInternal(Object o, int index)
 {
     try
     {
         Object value = _field.GetValue(o);
         return(EnumerableFastPropertyGetter.GetEnumerable(value, index));
     }
     catch (InvalidCastException e)
     {
         throw PropertyUtility.GetMismatchException(_field, o, e);
     }
     catch (PropertyAccessException)
     {
         throw;
     }
     catch (Exception e)
     {
         throw new PropertyAccessException(e);
     }
 }
 private Object GetBeanPropInternal(Object o, int index)
 {
     try
     {
         Object value = _method.Invoke(o, null);
         return(EnumerableFastPropertyGetter.GetEnumerable(value, index));
     }
     catch (InvalidCastException e)
     {
         throw PropertyUtility.GetMismatchException(_method, o, e);
     }
     catch (PropertyAccessException)
     {
         throw;
     }
     catch (Exception e)
     {
         throw new PropertyAccessException(e);
     }
 }
        public object GetBeanPropInternal(
            object @object,
            int index)
        {
            try {
                var value = _method.Invoke(@object, null);
                var valueList = value.AsObjectList(MagicMarker.SingletonInstance);
                if (valueList != null) {
                    if (valueList.Count <= index) {
                        return null;
                    }

                    return valueList[index];
                }

                return null;
            }
            catch (InvalidCastException e) {
                throw PropertyUtility.GetMismatchException(_method, @object, e);
            }
        }