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); } }
public bool IsExistsProperty(EventBean eventBean) { DynamicPropertyDescriptor desc = GetPopulateCache(eventBean.Underlying); if (desc.GetMethod() == null) { return(false); } return(true); }
public Object Get(EventBean eventBean) { DynamicPropertyDescriptor desc = GetPopulateCache(eventBean.Underlying); if (desc.GetMethod() == null) { return(null); } return(Call(desc, eventBean.Underlying)); }
public bool IsBeanExistsProperty(Object @object) { DynamicPropertyDescriptor desc = GetPopulateCache(@object); if (desc.GetMethod() == null) { return(false); } return(true); }
public Object GetBeanProp(Object @object) { DynamicPropertyDescriptor desc = GetPopulateCache(@object); if (desc.GetMethod() == null) { return(null); } return(Call(desc, @object)); }
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); } }
private DynamicPropertyDescriptor GetPopulateCache(Object obj) { // Check if the method is already there Type target = obj.GetType(); foreach (DynamicPropertyDescriptor desc in _cache) { if (desc.GetClazz() == target) { return(desc); } } // need to add it using (_iLock.Acquire()) { foreach (DynamicPropertyDescriptor desc in _cache) { if (desc.GetClazz() == target) { return(desc); } } // Lookup method to use MethodInfo method = DetermineMethod(target); // Cache descriptor and create fast method DynamicPropertyDescriptor propertyDescriptor; if (method == null) { propertyDescriptor = new DynamicPropertyDescriptor(target, null, false); } else { FastClass fastClass = FastClass.Create(target); FastMethod fastMethod = fastClass.GetMethod(method); propertyDescriptor = new DynamicPropertyDescriptor(target, fastMethod, fastMethod.ParameterCount > 0); } _cache.Add(propertyDescriptor); return(propertyDescriptor); } }
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); } }
private static DynamicPropertyDescriptor GetPopulateCache(CopyOnWriteList <DynamicPropertyDescriptor> cache, DynamicPropertyGetterBase dynamicPropertyGetterBase, Object obj, EventAdapterService eventAdapterService) { // Check if the method is already there var target = obj.GetType(); foreach (DynamicPropertyDescriptor desc in cache) { if (desc.Clazz == target) { return(desc); } } // need to add it lock (dynamicPropertyGetterBase) { foreach (DynamicPropertyDescriptor desc in cache) { if (desc.Clazz == target) { return(desc); } } // Lookup method to use var method = dynamicPropertyGetterBase.DetermineMethod(target); // Cache descriptor and create fast method DynamicPropertyDescriptor propertyDescriptor; if (method == null) { propertyDescriptor = new DynamicPropertyDescriptor(target, null, false); } else { var fastClass = FastClass.Create(target); var fastMethod = fastClass.GetMethod(method); propertyDescriptor = new DynamicPropertyDescriptor(target, fastMethod, fastMethod.ParameterCount > 0); } cache.Add(propertyDescriptor); return(propertyDescriptor); } }
/// <summary> /// Call the getter to obtains the return result object, or null if no such method /// exists. /// </summary> /// <param name="descriptor">provides method 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(DynamicPropertyDescriptor descriptor, Object underlying);