/// <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); }
/// <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); } }
/// <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); } }
public object GetBeanProp(object @object) { try { return _method.Invoke(@object, null); } catch (ArgumentException e) { throw PropertyUtility.GetArgumentException(_method, e); } catch (MemberAccessException e) { throw PropertyUtility.GetMemberAccessException(_method, e); } catch (TargetException e) { throw PropertyUtility.GetTargetException(_method, 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 o, Object key) { try { return(_method.Invoke(o, new[] { key })); } catch (InvalidCastException e) { throw PropertyUtility.GetMismatchException(_method, o, e); } catch (TargetException e) { throw PropertyUtility.GetTargetException(_method, e); } catch (TargetInvocationException e) { throw PropertyUtility.GetInvocationTargetException(_method, e); } catch (ArgumentException e) { throw PropertyUtility.GetIllegalArgumentException(_method, e); } }
private object GetBeanPropInternal( object @object, object key) { try { return _method.Invoke(@object, new[] {key}); } catch (InvalidCastException e) { throw PropertyUtility.GetMismatchException(_method, @object, e); } catch (TargetInvocationException e) { throw PropertyUtility.GetTargetException(_method, e); } catch (TargetException e) { throw PropertyUtility.GetTargetException(_method, e); } catch (MemberAccessException e) { throw PropertyUtility.GetMemberAccessException(_method, e); } catch (ArgumentException e) { throw PropertyUtility.GetArgumentException(_method, e); } }
public bool GetBeanPropExistsInternal( object @object, object key) { try { var result = _method.Invoke(@object, null); return CollectionUtil.GetMapKeyExistsChecked(result, key); } catch (InvalidCastException e) { throw PropertyUtility.GetMismatchException(_method, @object, e); } catch (TargetException e) { throw PropertyUtility.GetTargetException(_method, e); } catch (TargetInvocationException e) { throw PropertyUtility.GetTargetException(_method, e); } catch (MemberAccessException e) { throw PropertyUtility.GetMemberAccessException(_method, e); } catch (ArgumentException e) { throw PropertyUtility.GetArgumentException(_method, e); } }
private bool GetBeanPropInternalExists( object @object, int index) { try { var value = (Array) _prop.GetValue(@object); return CollectionUtil.ArrayExistsAtIndex(value, index); } catch (InvalidCastException e) { throw PropertyUtility.GetMismatchException(_prop, @object, e); } catch (TargetException e) { throw PropertyUtility.GetTargetException(_prop, e); } catch (TargetInvocationException e) { throw PropertyUtility.GetTargetException(_prop, e); } catch (MemberAccessException e) { throw PropertyUtility.GetMemberAccessException(_prop, e); } catch (ArgumentException e) { throw PropertyUtility.GetArgumentException(_prop, e); } }
private object GetBeanPropInternal( object @object, int index) { try { var value = (Array) _method.Invoke(@object, null); return CollectionUtil.ArrayValueAtIndex(value, index); } catch (InvalidCastException e) { throw PropertyUtility.GetMismatchException(_method, @object, e); } catch (TargetException e) { throw PropertyUtility.GetTargetException(_method, e); } catch (TargetInvocationException e) { throw PropertyUtility.GetTargetException(_method, e); } catch (MemberAccessException e) { throw PropertyUtility.GetMemberAccessException(_method, e); } catch (ArgumentException e) { throw PropertyUtility.GetArgumentException(_method, e); } }
public object GetBeanPropInternal( 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 (TargetException e) { throw PropertyUtility.GetTargetException(_property, e); } catch (TargetInvocationException e) { throw PropertyUtility.GetTargetException(_property, e); } catch (MemberAccessException e) { throw PropertyUtility.GetMemberAccessException(_property, e); } catch (ArgumentException e) { throw PropertyUtility.GetArgumentException(_property, e); } }