/// <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); } }
/// <summary> /// NOTE: Code-generation-invoked method, method name and parameter order matters /// </summary> /// <param name="clazz">class</param> /// <param name="field">field</param> /// <param name="cache">cache</param> /// <returns>descriptor</returns> public static DynamicPropertyDescriptorByField DynamicPropertyCacheAdd( Type clazz, FieldInfo field, CopyOnWriteList <DynamicPropertyDescriptorByField> cache) { var propertyDescriptor = new DynamicPropertyDescriptorByField(clazz, field); cache.Add(propertyDescriptor); return(propertyDescriptor); }
/// <summary> /// NOTE: Code-generation-invoked method, method name and parameter order matters /// </summary> /// <param name="descriptor">desc</param> /// <param name="underlying">underlying</param> /// <returns>value</returns> public static object DynamicSimplePropertyCall( DynamicPropertyDescriptorByField descriptor, object underlying) { try { return(descriptor.Field.GetValue(underlying)); } catch (Exception ex) { throw HandleException(descriptor, underlying, 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( 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); } }
/// <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">throwable</param> /// <returns>exception</returns> public static PropertyAccessException HandleException( DynamicPropertyDescriptorByField descriptor, object underlying, Exception ex) { if (ex is InvalidCastException invalidCastException) { throw PropertyUtility.GetMismatchException(descriptor.Field, underlying, invalidCastException); } if (ex is ArgumentException argumentException) { throw PropertyUtility.GetArgumentException(descriptor.Field, argumentException); } if (ex is MemberAccessException memberAccessException) { throw PropertyUtility.GetMemberAccessException(descriptor.Field, memberAccessException); } throw PropertyUtility.GetGeneralException(descriptor.Field, ex); }
protected override object Call( DynamicPropertyDescriptorByField descriptor, object underlying) { return(DynamicMappedPropertyGet(descriptor, underlying, _key)); }
protected override object Call( DynamicPropertyDescriptorByField descriptor, object underlying) { return(DynamicSimplePropertyCall(descriptor, underlying)); }
/// <summary> /// Call the getter to obtains the return result object, or null if no such field exists. /// </summary> /// <param name="descriptor">provides field information for the class</param> /// <param name="underlying">is the underlying object to ask for the property value</param> /// <returns>underlying</returns> protected abstract object Call( DynamicPropertyDescriptorByField descriptor, object underlying);