Пример #1
0
        internal MSAst Call(string methodName, MSAst instance = null, Type type = null, params MSAst[] arguments)
        {
            if (((instance == null) && (type == null)) || ((instance != null) && (type != null)))
            {
                throw new ArgumentException("Either 'instance' or 'type' must be specified, but not both.");
            }

            List <MethodBase> candidates;

            var isCandidate =
                (Func <MethodBase, bool>)
                    (m => (m.Name == methodName) &&
                    ((m.GetParameters().Length == arguments.Length) ||
                     (BinderHelpers.IsParamsMethod(m) && ((m.GetParameters().Length + 1) <= arguments.Length))));

            if (type != null)
            {
                candidates = type
                             .GetMethods(BindingFlags.Public | BindingFlags.Static)
                             .Where(isCandidate)
                             .Cast <MethodBase>()
                             .ToList();
            }
            else
            {
                candidates = instance.Type
                             .GetMethods(BindingFlags.Public | BindingFlags.Static)
                             .Where(isCandidate)
                             .Cast <MethodBase>()
                             .ToList();
            }

            return(_binder.Binder.CallMethod(
                       _sxeContext.OverloadResolver.CreateOverloadResolver(
                           arguments.Select(o => DynamicUtils.ObjectToMetaObject(null, o)).ToList(),
                           new CallSignature(arguments.Length),
                           CallTypes.None),
                       candidates).Expression);
        }