public override object GetValue(object obj, object[] index)
        {
            if ((index == null || index.Length == 0) && RuntimeFeature.IsDynamicCodeSupported)
            {
                /*FIXME we should check if the number of arguments matches the expected one, otherwise the error message will be pretty criptic.*/
                if (cached_getter == null)
                {
                    MethodInfo method = GetGetMethod(true);
                    if (method == null)
                    {
                        throw new ArgumentException($"Get Method not found for '{Name}'");
                    }
                    if (!DeclaringType.IsValueType && !PropertyType.IsByRef && !method.ContainsGenericParameters)                       //FIXME find a way to build an invoke delegate for value types.
                    {
                        cached_getter = CreateGetterDelegate(method);
                        // The try-catch preserves the .Invoke () behaviour
                        try {
                            return(cached_getter(obj));
                        } catch (Exception ex) {
                            throw new TargetInvocationException(ex);
                        }
                    }
                }
                else
                {
                    try {
                        return(cached_getter(obj));
                    } catch (Exception ex) {
                        throw new TargetInvocationException(ex);
                    }
                }
            }

            return(GetValue(obj, BindingFlags.Default, null, index, null));
        }
Beispiel #2
0
        public override object GetValue(object obj, object[] index)
        {
            if (index == null || index.Length == 0)
            {
                /*FIXME we should check if the number of arguments matches the expected one, otherwise the error message will be pretty criptic.*/
#if !MONOTOUCH
                if (cached_getter == null)
                {
                    if (!DeclaringType.IsValueType)                       //FIXME find a way to build an invoke delegate for value types.
                    {
                        MethodInfo method = GetGetMethod(true);
                        if (method == null)
                        {
                            throw new ArgumentException("Get Method not found for '" + Name + "'");
                        }
                        cached_getter = CreateGetterDelegate(method);
                        return(cached_getter(obj));
                    }
                }
                else
                {
                    return(cached_getter(obj));
                }
#endif
            }

            return(GetValue(obj, BindingFlags.Default, null, index, null));
        }