Python.Runtime.MethodBinder.MatchByTypeSig C# (CSharp) Méthode

MatchByTypeSig() static private méthode

static private MatchByTypeSig ( MethodInfo msig, IntPtr psig ) : MethodInfo
msig System.Reflection.MethodInfo
psig System.IntPtr
Résultat System.Reflection.MethodInfo
 	internal static MethodInfo MatchByTypeSig(MethodInfo[] msig, 
						  IntPtr psig) {
 	    IntPtr args = psig;
 	    bool free = false;
 
 	    if (!Runtime.PyTuple_Check(psig)) {
 		args = Runtime.PyTuple_New(1);
 		Runtime.Incref(psig);
 		Runtime.PyTuple_SetItem(args, 0, psig);
 		free = true;
 	    }
 
 	    int plen = Runtime.PyTuple_Size(args);
 	    MethodInfo match = null;
 
 	    // XXX: what about out args, etc.?
 
 	    for (int i = 0; i < msig.Length; i++) {
 		ParameterInfo[] pi = msig[i].GetParameters();
 		if (pi.Length != plen) {
 		    continue;
 		}
		bool matched = true;
 		for (int n = 0; n < pi.Length; n++) {
 		    IntPtr p = Runtime.PyTuple_GetItem(args, n);
 		    if (p == IntPtr.Zero) {
 			Exceptions.Clear();
 			break;
 		    }
 		    ClassBase c = ManagedType.GetManagedObject(p) as ClassBase;
 		    Type t = (c != null) ? c.type : 
 			     Converter.GetTypeByAlias(p);

 		    if (t == null) {
 			break;
 		    }
 		    if (t != pi[n].ParameterType) {
			matched = false;
 			break;
 		    }
 		}
		if (matched) {
		    match = msig[i];
		    break;
		}
 	    }
 
 	    if (free) {
 		Runtime.Decref(args);
 	    }
 
 	    return match;
 	}
 

Usage Example

Exemple #1
0
        public static IntPtr mp_subscript(IntPtr tp, IntPtr idx)
        {
            MethodBinding self = (MethodBinding)GetManagedObject(tp);
            MethodInfo    sig  = MethodBinder.MatchByTypeSig(self.m.info, idx);

            if (sig == null)
            {
                return(Exceptions.RaiseTypeError(
                           "No match found for signature"
                           ));
            }
            MethodBinding mb = new MethodBinding(self.m, self.target);

            mb.info = sig;
            Runtime.Incref(mb.pyHandle);
            return(mb.pyHandle);
        }