Exemplo n.º 1
0
        // This will find the right overloaded method if the argValues from soap have type information,
        // By default parameters will be of type string, this could lead to a wrong choice of methodbase.
        void ResolveOverloadedMethod(RuntimeType t, String methodName, ArrayList argNames, ArrayList argValues)
        {
            MethodInfo[] mi = t.GetMemberMethod(methodName,
                                                MethodCall.LookupPublic,
                                                CallingConventions.Any,
                                                null,
                                                -1,
                                                false);
            if (mi!=null)
            {
                if (mi.Length == 1)
                {
                    MI = mi[0];
                }
                else if (mi.Length > 1)
                {
                    for (int i=0; i<mi.Length; i++)
                    {
                        ParameterInfo[] piA = mi[i].GetParameters();
                        bool bMatch = true;
                        if (piA.Length == argValues.Count)
                        {
                            for (int j=0; j<piA.Length; j++)
                            {
                                Type ptype = piA[j].ParameterType;
                                if (ptype.IsByRef)
                                    ptype= ptype.GetElementType();

                                if (ptype != argValues[j].GetType())
                                {
                                    bMatch = false;
                                    break;
                                }

                            }
                            if (bMatch)
                            {
                                MI = mi[i];
                                break;
                            }
                        } 
                    }

                    if (MI == null)
                    {
                        throw new RemotingException(
                            Environment.GetResourceString(
                                "Remoting_AmbiguousMethod"));
                    }
                }     
            }
        }
Exemplo n.º 2
0
        // Helper that gets called when we attempt to resolve a method
        // without an accompanying methodSignature ... current thinking is
        // that we should make a good faith attempt by matching argument
        // counts
        void ResolveOverloadedMethod(RuntimeType t)
        {
            if (args == null) // args is null the first call from soap because we havem't passed the arguments yet.
                return;

            MethodInfo[] mi = t.GetMemberMethod(methodName,
                                                MethodCall.LookupPublic,
                                                CallingConventions.Any,
                                                null,
                                                -1,
                                                false);
            if (mi!=null)
            {
                if (mi.Length == 1)
                {
                    MI = mi[0];
                }
                else if (mi.Length > 1)
                {
                    int argCount = args.Length;
                    int match = 0;
                    int iMatch = -1;
                    for (int i=0; i<mi.Length; i++)
                    {
                        if (mi[i].GetParameters().Length == argCount)
                        {
                            match++;
                            iMatch = i;
                        } 
                    }

                    // We will let resolve succeed if exactly one
                    // of the overloaded methods matches in terms
                    // of argCount
                    if (match == 1)
                    {
                        MI = mi[iMatch]; 
                    }
                    else if (match > 1)
                    {
                        throw new RemotingException(
                            Environment.GetResourceString(
                                "Remoting_AmbiguousMethod"));
                    }
                }     
            }
        }