Parse() публичный статический Метод

Parses assignment expressions. This method basically just prepares the parameters for a call to IdentifierExp.Assign(). Reference that method for more information on this method's parameters.
public static Parse ( List envChain, List envNames, List envIndices, CseObject rhs ) : CseObject
envChain List /// List of CseObjects from the chain expression of the lhs. /// This makes up the list of environment objects. ///
envNames List List of field/property names in the lhs chain expression.
envIndices List /// List of array indices for each array in the lhs chain expression. /// For each non-array, the envIndices at that index is null. ///
rhs CseObject Rhs expression
Результат CseObject
Пример #1
0
        ///
        /// <summary>
        ///		Parses method calls
        /// </summary>
        ///
        /// <param name="environment">The environment containing the method</param>
        /// <param name="methName">Name of the method</param>
        /// <param name="args">CseObject array containing arguments to be sent to the method. Each CseObject is one argument</param>
        ///
        /// <returns>CseObject containing the return result of the method call or CseObject containing null if method is void</returns>
        ///
        /// <exception cref="CseLogicExceptionType.METHOD_CALL_AMBIGUOUS" />
        /// <exception cref="CseLogicExceptionType.METHOD_CANT_IMPLICITLY_COERCE_ARGS" />
        /// <exception cref="CseLogicExceptionType.METHOD_DOESNT_EXIST" />
        /// <exception cref="CseLogicExceptionType.METHOD_EXISTS_BUT_CANT_BE_INVOKED" />
        ///
        public static CseObject Parse(CseObject environment, string methName, List <CseObject> args)
        {
            MethResSettings mrSettings = new MethResSettings()
            {
                Args = (args == null ? new CseObject[] { } : args.ToArray()),
                Env  = environment.Value,
                Name = methName
            };
            List <MethResObject> appMeths = MethRes.GetApplicableMembers(mrSettings);

            if (appMeths.Count == 0)
            {
                mrSettings.IsExtInvocation = true;
                appMeths = MethRes.GetApplicableMembers(mrSettings);
            }

            MethodInfo mi      = null;
            Type       envType = TypeExp.GetTypeObj(environment.Value);

            try {
                switch (appMeths.Count)
                {
                // No methods exist with that name
                case 0:
                    // TODO: doesn't exist OR no applicable methods can be called
                    throw new CseLogicException(CseLogicExceptionType.METHOD_DOESNT_EXIST, methName);

                // Only 1 method exists with that name, so try to do what's necessary to coerce args (if they exist)
                // to match its signature.
                case 1:
                    MethResObject mrObj = appMeths[0];

                    if (args != null)
                    {
                        for (int i = 0; i < args.Count; i++)
                        {
                            try {
                                args[i] = CastExp.Parse(environment, mrObj.MethInfo.GetParameters()[i].ParameterType.Name, args[i]);
                            }
                            catch (CseLogicException) {
                                // f**k it, continue
                            }
                        }
                    }
                    //NarrowAllIntTypes(ref args);

                    mi = mrObj.MethInfo;
                    break;

                // Method is overloaded.
                // Idea is to simulate C#'s best match algorithm for finding the most appropriate method to call
                // and if still unsure, throw exception so user can use casting for further clarification.
                default:
                    Type[] types = GetTypeArray(args);

                    mi = envType.GetMethod(methName, findFlags | BindingFlags.ExactBinding, null, types, null);

                    if (mi != null)
                    {
                        break;
                    }

                    if (CanCoerce(args))
                    {
                        NarrowAllIntTypes(ref args);
                        types = GetTypeArray(args);
                    }

                    MethodInfo tryMeth = envType.GetMethod(methName, findFlags, null, types, null);
                    foreach (MethResObject m in appMeths)
                    {
                        if (m.MethInfo == tryMeth)
                        {
                            mi = tryMeth;
                            break;
                        }
                    }

                    if (mi != null)
                    {
                        break;
                    }

                    // TODO: Attempt to coerce args to formal param types of overloaded methods



                    if (mi == null)
                    {
                        throw new CseLogicException(CseLogicExceptionType.METHOD_CALL_AMBIGUOUS, methName);
                    }

                    break;
                }
            }
            catch (AmbiguousMatchException) {
                throw new CseLogicException(CseLogicExceptionType.METHOD_CALL_AMBIGUOUS, methName);
            }
            catch (CseLogicException) {
                throw;
            }
            catch {
                throw new CseLogicException(CseLogicExceptionType.METHOD_EXISTS_BUT_CANT_BE_INVOKED, methName);
            }

            if (mi == null)
            {
                throw new CseLogicException(CseLogicExceptionType.METHOD_EXISTS_BUT_CANT_BE_INVOKED, methName);
            }
            else
            {
                dynamic result = mi.Invoke(environment.Value, GetObjArgs(args));

                CseObject xo = new CseObject(result);
                xo.CompileTimeType = mi.ReturnType;

                if (args != null)
                {
                    foreach (CseObject arg in args)
                    {
                        if (arg.CallMod != CallArgMod.VAL)
                        {
                            AssignExp.Parse(arg.EnvChain, arg.EnvNames, arg.EnvIndices, arg.Value);
                        }
                    }
                }

                return(xo);
            }
        }