SelectMethod() public abstract method

public abstract SelectMethod ( BindingFlags bindingAttr, Array match, Array types, Array modifiers ) : MethodBase
bindingAttr BindingFlags
match Array
types Array
modifiers Array
return MethodBase
Esempio n. 1
0
        public override MethodBase SelectMethod(BindingFlags bindingAttr, MethodBase[] match, Type[] argumentTypes, ParameterModifier[] modifiers)
#endif
        {
            if (match.Length == 0)
            {
                return(null);
            }
#if CSHARP8
            MethodBase?result = null;
#else
            MethodBase result = null;
#endif
            // SelectMethod on the default binder throws an exception if passed
            // typebuilders. this comes up when trying to bind to proxy methods
            // during analysis when (the proxy type is not yet complete). we
            // skip the default binder in this case and fall back on our own logic
            bool allRuntimeTypes = true;
            for (var i = 0; i < argumentTypes.Length; i++)
            {
                if (argumentTypes[i] is System.Reflection.Emit.TypeBuilder)
                {
                    allRuntimeTypes = false;
                    break;
                }
            }
            if (allRuntimeTypes)
            {
                result = _binder.SelectMethod(bindingAttr, match, argumentTypes, modifiers);
            }
            if (result != null)
            {
                return(result);
            }
            foreach (var candidate in match)
            {
                if (MatchByMagicBindingRules(bindingAttr, candidate, argumentTypes, modifiers))
                {
                    if (result != null)
                    {
                        throw new AmbiguousMatchException();
                    }
                    else
                    {
                        result = candidate;
                        continue;
                    }
                }
            }

            return(result);
        }
Esempio n. 2
0
        /// <include file='doc\Module.uex' path='docs/doc[@for="Module.GetMethodImpl"]/*' />
        protected virtual MethodInfo GetMethodImpl(String name, BindingFlags bindingAttr, Binder binder,
                                                   CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
        {
            if (binder == null)
            {
                binder = Type.DefaultBinder;
            }

            // If the types array is null that means we don't care about the arguments to the method, we will simply
            // return the one that matchs or throw an argument error...
            int argCnt = (types != null) ? types.Length : -1;

            MethodBase[] meths = InternalGetMethod(name,
                                                   bindingAttr,
                                                   callConvention,
                                                   types,
                                                   argCnt);
            // at this point a proper filter with respect to BindingAttributes and calling convention already happened
            if (meths == null)
            {
                return(null);
            }
            if (argCnt <= 0)
            {
                // either no args or a method with 0 args was specified
                if (meths.Length == 1)
                {
                    return((MethodInfo)meths[0]);
                }
                else if (argCnt < 0)
                {
                    // There are multiple methods with the same name. Check to see if they are all
                    // new slots with the same name and sig.
                    foreach (MethodBase m in meths)
                    {
                        if (!System.DefaultBinder.CompareMethodSigAndName(m, meths[0]))
                        {
                            // One of the methods is not a new slot. So the match is ambigous.
                            throw new AmbiguousMatchException(Environment.GetResourceString("RFLCT.Ambiguous"));
                        }
                    }

                    // All the methods are new slots with the same name and sig so return the most derived one.
                    return((MethodInfo)System.DefaultBinder.FindMostDerivedNewSlotMeth(meths, meths.Length));
                }
            }

            return((MethodInfo)binder.SelectMethod(bindingAttr, meths, types, modifiers));
        }
Esempio n. 3
0
		protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr, Binder binder,
								       CallingConventions callConvention, Type[] types,
								       ParameterModifier[] modifiers)
		{
			check_created ();

			if (created == typeof (object)) {
				/* 
				 * This happens when building corlib. Calling created.GetConstructor 
				 * would return constructors from the real mscorlib, instead of the
				 * newly built one.
				 */

				if (ctors == null)
					return null;
 
				ConstructorBuilder found = null;
				int count = 0;
			
				foreach (ConstructorBuilder cb in ctors) {
					if (callConvention != CallingConventions.Any && cb.CallingConvention != callConvention)
						continue;
					found = cb;
					count++;
				}

				if (count == 0)
					return null;
				if (types == null) {
					if (count > 1)
						throw new AmbiguousMatchException ();
					return found;
				}
				MethodBase[] match = new MethodBase [count];
				if (count == 1)
					match [0] = found;
				else {
					count = 0;
					foreach (ConstructorInfo m in ctors) {
						if (callConvention != CallingConventions.Any && m.CallingConvention != callConvention)
							continue;
						match [count++] = m;
					}
				}
				if (binder == null)
					binder = DefaultBinder;
				return (ConstructorInfo) binder.SelectMethod (bindingAttr, match,
															  types, modifiers);
			}

			return created.GetConstructor (bindingAttr, binder, 
				callConvention, types, modifiers);
		}
Esempio n. 4
0
		internal static ConstructorInfo GetConstructorImpl (ConstructorInfo[] methods, BindingFlags bindingAttr,
								       Binder binder,
								       CallingConventions callConvention,
								       Type[] types,
								       ParameterModifier[] modifiers)
		{
			if (bindingAttr == BindingFlags.Default)
				bindingAttr = BindingFlags.Public | BindingFlags.Instance;

			ConstructorInfo found = null;
			MethodBase[] match;
			int count = 0;
			foreach (ConstructorInfo m in methods) {
				// Under MS.NET, Standard|HasThis matches Standard...
				if (callConvention != CallingConventions.Any && ((m.CallingConvention & callConvention) != callConvention))
					continue;
				found = m;
				count++;
			}
			if (count == 0)
				return null;
			if (types == null) {
				if (count > 1)
					throw new AmbiguousMatchException ();
				return (ConstructorInfo) CheckMethodSecurity (found);
			}
			match = new MethodBase [count];
			if (count == 1)
				match [0] = found;
			else {
				count = 0;
				foreach (ConstructorInfo m in methods) {
					if (callConvention != CallingConventions.Any && ((m.CallingConvention & callConvention) != callConvention))
						continue;
					match [count++] = m;
				}
			}
			if (binder == null)
				binder = Binder.DefaultBinder;
			return (ConstructorInfo) CheckMethodSecurity (binder.SelectMethod (bindingAttr, match, types, modifiers));
		}
Esempio n. 5
0
		protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr,
							     Binder binder,
							     CallingConventions callConvention,
							     Type[] types, ParameterModifier[] modifiers)
		{
			bool ignoreCase = ((bindingAttr & BindingFlags.IgnoreCase) != 0);
			MethodInfo[] methods = GetMethodsByName (name, bindingAttr, ignoreCase, this);
			MethodInfo found = null;
			MethodBase[] match;
			int count = 0;
			
			foreach (MethodInfo m in methods) {
				// Under MS.NET, Standard|HasThis matches Standard...
				if (callConvention != CallingConventions.Any && ((m.CallingConvention & callConvention) != callConvention))
					continue;
				found = m;
				count++;
			}

			if (count == 0)
				return null;
			
			if (count == 1 && types == null) 
				return (MethodInfo) CheckMethodSecurity (found);

			match = new MethodBase [count];
			if (count == 1)
				match [0] = found;
			else {
				count = 0;
				foreach (MethodInfo m in methods) {
					if (callConvention != CallingConventions.Any && ((m.CallingConvention & callConvention) != callConvention))
						continue;
					match [count++] = m;
				}
			}

			if (types == null) 
				return (MethodInfo) CheckMethodSecurity (Binder.FindMostDerivedMatch (match));

			if (binder == null)
				binder = Binder.DefaultBinder;
			
			return (MethodInfo) CheckMethodSecurity (binder.SelectMethod (bindingAttr, match, types, modifiers));
		}
 public MethodInfo GetMethod(string name, BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers)
 {
     MemberInfo[] member = this.GetMember(name, bindingAttr);
     if (member.Length == 1)
     {
         return (member[0] as MethodInfo);
     }
     int num = 0;
     foreach (MemberInfo info in member)
     {
         if (info.MemberType == MemberTypes.Method)
         {
             num++;
         }
     }
     if (num == 0)
     {
         return null;
     }
     MethodInfo[] match = new MethodInfo[num];
     num = 0;
     foreach (MemberInfo info2 in member)
     {
         if (info2.MemberType == MemberTypes.Method)
         {
             match[num++] = (MethodInfo) info2;
         }
     }
     if (binder == null)
     {
         binder = JSBinder.ob;
     }
     return (MethodInfo) binder.SelectMethod(bindingAttr, match, types, modifiers);
 }
Esempio n. 7
0
        internal MethodInfo GetMethodImplInternal(String name,
                                                  BindingFlags bindingAttr,
                                                  Binder binder,
                                                  CallingConventions callConvention, 
                                                  Type[] types,
                                                  ParameterModifier[] modifiers, 
                                                  bool verifyAccess)
        {       
            if (binder == null)
                binder = DefaultBinder;
            
            // If the types array is null that means we don't care about the arguments to the method, we will simply
            //  return the one that matchs or throw an argument error...
            int argCnt = (types != null) ? types.Length : -1;
            MethodBase[] meths = GetMemberMethod(name, 
                                                 bindingAttr, 
                                                 callConvention, 
                                                 types, 
                                                 argCnt,
                                                 verifyAccess);
            // at this point a proper filter with respect to BindingAttributes and calling convention already happened
            if (meths == null)
                return null;
            if (argCnt <= 0) {
                // either no args or a method with 0 args was specified
                if (meths.Length == 1)
                    return (MethodInfo) meths[0];
                else if (argCnt < 0) {
                    // There are multiple methods with the same name. Check to see if they are all
                    // new slots with the same name and sig.
                    foreach(MethodBase m in meths) {
                        if (!System.DefaultBinder.CompareMethodSigAndName(m, meths[0]))
                            // One of the methods is not a new slot. So the match is ambigous.
                            throw new AmbiguousMatchException(Environment.GetResourceString("RFLCT.Ambiguous"));
                        }

                    // All the methods are new slots with the same name and sig so return the most derived one.
                    return (MethodInfo) System.DefaultBinder.FindMostDerivedNewSlotMeth(meths, meths.Length);
                }
            }   
            
            return (MethodInfo) binder.SelectMethod(bindingAttr,meths,types,modifiers);                  
        }
Esempio n. 8
0
     internal ConstructorInfo GetConstructorImplInternal(BindingFlags bindingAttr,
                                                         Binder binder,
                                                         CallingConventions callConvention, 
                                                         Type[] types,
                                                         ParameterModifier[] modifiers, 
                                                         bool verifyAccess)
     {
 
         // Must provide some types (Type[0] for nothing)
         if (types == null)
             throw new ArgumentNullException("types");
         
         if (binder == null)
             binder = DefaultBinder;
         
         int argCnt = types.Length;
         bool isDelegate;
         MethodBase[] cons = GetMemberCons(bindingAttr, 
                                           callConvention, 
                                           types,
                                           argCnt, 
                                           verifyAccess, 
                                           /*binder == DefaultBinder, */
                                           out isDelegate);
         if (cons == null)
             return null;
         
         if (argCnt == 0 && cons.Length == 1) { 
             ParameterInfo[] pars = cons[0].GetParameters();
             if (pars == null || pars.Length == 0) {
                 return (ConstructorInfo) cons[0];
             }
         }
         if ((bindingAttr & BindingFlags.ExactBinding) != 0)
             return (ConstructorInfo) System.DefaultBinder.ExactBinding(cons,types,modifiers);
         
         return (ConstructorInfo) binder.SelectMethod(bindingAttr,cons,types,modifiers);
     }   
 public MethodInfo GetMethod(String name, BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers){
   MemberInfo[] members = this.GetMember(name, bindingAttr);
   if (members.Length == 1) return members[0] as MethodInfo;
   int methodCount = 0;
   foreach (MemberInfo member in members)
     if (member.MemberType == MemberTypes.Method) methodCount++;
   if (methodCount == 0) return null;
   MethodInfo[] methods = new MethodInfo[methodCount];
   methodCount = 0;
   foreach (MemberInfo member in members)
     if (member.MemberType == MemberTypes.Method) methods[methodCount++] = (MethodInfo)member;
   if (binder == null) binder = JSBinder.ob;
   return (MethodInfo)binder.SelectMethod(bindingAttr, methods, types, modifiers);
 }