//
        // GetMethod (called by system.RuntimeType.GetMethodImpl)
        //

        public static MethodInfo GetMethod(string name, BindingFlags bindingAttr,
                                           Binder binder, CallingConventions callConvention,
                                           Type[] types, ParameterModifier[] modifiers,
                                           RuntimeType initialType)
        {
            ThrowHelper.ThrowIfNull(name);
            RuntimeMethodInfo.ValidateGetMethod(binder, callConvention, types, modifiers);

            RuntimeMethodInfo foundMethod = null;

            BindingFlagsIterator.Run(bindingAttr, initialType, MemberTypes.Method,
                                     (javaAccessibleObject) =>
            {
                #pragma warning disable 0436
                var javaMethod = (java.lang.reflect.Method)javaAccessibleObject;
                #pragma warning restore 0436

                string originalName = javaMethod.getName();
                var compareName     = RuntimeMethodInfo.AdjustedMethodName(originalName);

                if (name == compareName)
                {
                    javaMethod.setAccessible(true);
                    var jmodifiers = javaMethod.getModifiers();
                    foundMethod    = new RuntimeMethodInfo(javaMethod, jmodifiers, initialType,
                                                           originalName, compareName);
                    return(false); // stop iteration
                }

                return(true); // continue iteration
            });

            return(foundMethod);
        }
Example #2
0
        //
        // GetFields (called by system.RuntimeType.GetFields()
        //

        public static FieldInfo[] GetFields(BindingFlags bindingAttr, RuntimeType initialType)
        {
            var list = new System.Collections.Generic.List <FieldInfo>();

            BindingFlagsIterator.Run(bindingAttr, initialType, MemberTypes.Field,
                                     (javaAccessibleObject) =>
            {
                var javaField = (java.lang.reflect.Field)javaAccessibleObject;
                javaField.setAccessible(true);
                list.Add(new RuntimeFieldInfo(javaField, initialType));
                return(true);
            });

            return(list.ToArray());
        }
        //
        // GetFields (called by system.RuntimeType.GetFields()
        //

        public static FieldInfo[] GetFields(BindingFlags bindingAttr, RuntimeType initialType)
        {
            var list = new java.util.ArrayList();

            BindingFlagsIterator.Run(bindingAttr & ~BindingFlags.GetField,
                                     initialType, MemberTypes.Field,
                                     (javaAccessibleObject) =>
            {
                var javaField = (java.lang.reflect.Field)javaAccessibleObject;
                javaField.setAccessible(true);
                list.add(new RuntimeFieldInfo(javaField, initialType));
                return(true);
            });

            return((RuntimeFieldInfo[])list.toArray(new RuntimeFieldInfo[0]));
        }
Example #4
0
        //
        // GetConstructor (called by system.RuntimeType.GetConstructorImpl)
        //

        public static ConstructorInfo GetConstructor(BindingFlags bindingAttr, Binder binder,
                                                     CallingConventions callConvention,
                                                     Type[] types, ParameterModifier[] modifiers,
                                                     RuntimeType initialType)
        {
            RuntimeMethodInfo.ValidateGetMethod(binder, callConvention, types, modifiers);

            if (initialType.IsValueType)
            {
                return(null);
            }
            var numGenericArgsInInitialType = initialType.GetGenericArguments().Length;

            RuntimeConstructorInfo foundConstructor = null;

            BindingFlagsIterator.Run(bindingAttr, initialType, MemberTypes.Constructor,
                                     (javaAccessibleObject) =>
            {
                #pragma warning disable 0436
                var javaConstructor = (java.lang.reflect.Constructor)javaAccessibleObject;
                #pragma warning restore 0436

                var constructorTypes = DiscardClasses(initialType.JavaClassForArray(),
                                                      numGenericArgsInInitialType,
                                                      javaConstructor.getParameterTypes(),
                                                      out var hasGenericArgs,
                                                      out var hasUniqueArg);
                if (constructorTypes.Length == 0)
                {
                    javaConstructor.setAccessible(true);
                    foundConstructor = new RuntimeConstructorInfo(javaConstructor, initialType)
                    {
                        HasGenericArgs = hasGenericArgs,
                        HasUniqueArg   = hasUniqueArg,
                    };
                    return(false); // stop iteration
                }

                return(true); // continue iteration
            });
Example #5
0
        //
        // GetMethod (called by system.RuntimeType.GetMethodImpl)
        //

        public static MethodInfo GetMethod(string name, BindingFlags bindingAttr,
                                           Binder binder, CallingConventions callConvention,
                                           Type[] types, ParameterModifier[] modifiers,
                                           RuntimeType initialType)
        {
            //
            // validate parameters
            //

            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (binder != null)
            {
                throw new PlatformNotSupportedException("non-null binder");
            }
            if (callConvention != CallingConventions.Any)
            {
                throw new PlatformNotSupportedException("calling convention must be Any");
            }
            if (types != null)
            {
                throw new PlatformNotSupportedException("non-null types");
            }
            if (modifiers != null)
            {
                throw new PlatformNotSupportedException("non-null modifiers");
            }

            //
            // calculate modifier AND mask and result for matches
            //

            RuntimeMethodInfo foundMethod = null;

            BindingFlagsIterator.Run(bindingAttr, initialType, MemberTypes.Method,
                                     (javaAccessibleObject) =>
            {
                #pragma warning disable 0436
                var javaMethod = (java.lang.reflect.Method)javaAccessibleObject;
                #pragma warning restore 0436

                string originalName = javaMethod.getName();
                // note the actual suffix character below is configured
                // in CilMain.cs, with special considerations for Android.
                // we list all possible characters here, just in case.
                int idx = originalName.IndexOf('\u00AB'); // U+00AB Left-Pointing Double Angle Quotation Mark
                if (idx == -1)
                {
                    idx = originalName.IndexOf('\u00A1'); // U+00A1 Inverted Exclamation Mark
                }
                if (idx == -1)
                {
                    idx = originalName.IndexOf('(');
                }
                if (idx == -1)
                {
                    idx = originalName.IndexOf('!');
                }
                var compareName =
                    (idx == -1) ? originalName : originalName.Substring(0, idx);

                if (name == compareName)
                {
                    javaMethod.setAccessible(true);
                    var jmodifiers = javaMethod.getModifiers();
                    foundMethod    = new RuntimeMethodInfo(javaMethod, jmodifiers, initialType,
                                                           originalName, compareName);
                    return(false); // stop iteration
                }

                return(true); // continue iteration
            });

            return(foundMethod);
        }
        //
        // GetMethod (called by system.RuntimeType.GetPropertyImpl)
        //

        public static PropertyInfo GetProperty(string name, BindingFlags bindingAttr,
                                               Binder binder, Type returnType,
                                               Type[] types, ParameterModifier[] modifiers,
                                               RuntimeType initialType)
        {
            ThrowHelper.ThrowIfNull(name);

            if (types != null && types.Length != 0) // if indexed property
            {
                throw new PlatformNotSupportedException();
            }

            #pragma warning disable 0436
            java.lang.reflect.Method getMethod = null;
            java.lang.Class          getClass  = null;
            java.lang.reflect.Method setMethod = null;
            java.lang.Class          setClass  = null;
            #pragma warning restore 0436

            BindingFlagsIterator.Run(bindingAttr & ~BindingFlags.GetProperty,
                                     initialType, MemberTypes.Method,
                                     (javaAccessibleObject) =>
            {
                #pragma warning disable 0436
                var javaMethod = (java.lang.reflect.Method)javaAccessibleObject;
                #pragma warning restore 0436

                var cls = IsGetMethod(javaMethod, name, returnType);
                if (cls != null)
                {
                    getMethod = javaMethod;
                    getClass  = cls;
                }
                else
                {
                    cls = IsSetMethod(javaMethod, name, returnType);
                    if (cls != null)
                    {
                        setMethod = javaMethod;
                        setClass  = cls;
                    }
                }

                return(true);
            });

            if (getClass != null)
            {
                if (setClass != null && setClass != getClass)
                {
                    setMethod = null;
                }
            }
            else if (setClass != null)
            {
                getClass = setClass;
            }
            else // neither get nor set methods
            {
                return(null);
            }

            return(new RuntimePropertyInfo(getMethod, setMethod, getClass, initialType));