/// <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">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="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); } }
/// <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); } }
public static object GetPropertySimple( PropertyInfo property, object @object) { try { return(property.GetValue(@object)); } catch (ArgumentException e) { throw PropertyUtility.GetArgumentException(property, e); } catch (MemberAccessException e) { throw PropertyUtility.GetMemberAccessException(property, e); } }
public static object GetFieldSimple( FieldInfo field, object @object) { try { return(field.GetValue(@object)); } catch (ArgumentException e) { throw PropertyUtility.GetArgumentException(field, e); } catch (MemberAccessException e) { throw PropertyUtility.GetMemberAccessException(field, e); } }
public object GetBeanProp(object @object) { try { return _property.GetValue(@object); } catch (ArgumentException e) { throw PropertyUtility.GetArgumentException(_property, e); } catch (MemberAccessException e) { throw PropertyUtility.GetMemberAccessException(_property, e); } catch (TargetException e) { throw PropertyUtility.GetGeneralException(_property, 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); } }
/// <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); } }
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); } }
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 static object GetPropertyArray( PropertyInfo property, object @object, int index) { try { var value = property.GetValue(@object) as Array; if ((value == null) || (value.Length <= index)) { return(null); } return(value.GetValue(index)); } 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); } }
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 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); } }
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); } }
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); } }