Example #1
0
        public TypedValue Invoke(TypedValue instance, string memberName, Tree <T> parameters)
        {
            RuntimeMember member;
            var           parameterNames = new List <string>();
            int           parameterCount;

            if (memberName.StartsWith(namedParameterPrefix))
            {
                parameterNames = parameters.Branches.Alternate().Aggregate(new List <string>(),
                                                                           (names, parameter) => {
                    names.Add(Processor.ParseTree <T, string>(parameter));
                    return(names);
                });
                parameterCount = parameterNames.Count;
                member         = RuntimeType.FindInstance(instance.Value, new IdentifierName(memberName.Substring(namedParameterPrefix.Length)), parameterNames);
            }
            else
            {
                parameterCount = parameters.Branches.Count;
                member         = RuntimeType.FindInstance(instance.Value, new IdentifierName(memberName), parameterCount);
            }

            if (member == null)
            {
                return(TypedValue.MakeInvalid(new MemberMissingException(instance.Type, new IdentifierName(memberName).SourceName, parameterCount)));
            }

            object[] parameterList = memberName.StartsWith(namedParameterPrefix)
                ? GetNamedParameterList(instance, parameters, member, parameterNames)
                : GetParameterList(instance, parameters, member);
            return(member.Invoke(parameterList));
        }
        public TypedValue Invoke(TypedValue instance, MemberName memberName, Tree <Cell> parameters)
        {
            var member = MemberQuery.FindDirectInstance(instance.Value, new MemberSpecification(memberName));

            return(member.ForValue(
                       v => v.Invoke(new object[] {}),
                       () => TypedValue.MakeInvalid(new MemberMissingException(instance.Type, memberName.Name, 0))));
        }
Example #3
0
        public TypedValue Invoke(TypedValue instance, string prefixedMemberName, Tree <Cell> parameters)
        {
            var memberName = prefixedMemberName.Substring(1);
            var member     = RuntimeType.FindDirectInstance(instance.Value, new IdentifierName(memberName), 0);

            return(member != null
                            ? member.Invoke(new object[] {})
                            : TypedValue.MakeInvalid(new MemberMissingException(instance.Type, memberName, 0)));
        }
 public TypedValue InvokeSpecial(TypedValue instance, MemberName memberName, Tree <Cell> parameters)
 {
     if (memberName.Name != "akeyword")
     {
         return(TypedValue.MakeInvalid(new ApplicationException("argh")));
     }
     Field = "somevalue";
     return(TypedValue.Void);
 }
Example #5
0
        public bool TryInvoke(Processor <T> processor, TypedValue instance, string memberName, Tree <T> parameters,
                              ref TypedValue result)
        {
            RuntimeMember member = RuntimeType.FindInstance(instance.Value, memberName, parameters.Branches.Count);

            result = member != null
                         ? member.Invoke(GetParameterList(processor, instance, parameters, member))
                         : TypedValue.MakeInvalid(new MemberMissingException(instance.Type, memberName,
                                                                             parameters.Branches.Count));

            return(true);
        }
        public TypedValue Invoke(TypedValue instance, MemberName memberName, Tree <T> parameters)
        {
            RuntimeMember member;
            var           parameterNames = new List <string>();
            int           parameterCount;

            if (memberName.HasNamedParameters)
            {
                parameterNames = parameters.Branches.Alternate().Aggregate(new List <string>(),
                                                                           (names, parameter) => {
                    names.Add(Processor.ParseTree <T, string>(parameter));
                    return(names);
                });
                parameterCount = parameterNames.Count;
                member         = MemberQuery.FindInstance(Processor.FindMember, instance.Value,
                                                          new MemberSpecification(memberName).WithParameterNames(parameterNames));
            }
            else
            {
                parameterCount = parameters.Branches.Count;
                member         = MemberQuery.FindInstance(Processor.FindMember, instance.Value,
                                                          new MemberSpecification(memberName, parameterCount));
            }

            if (member == null)
            {
                return(TypedValue.MakeInvalid(new MemberMissingException(instance.Type, memberName.Name, parameterCount)));
            }

            var parameterList = memberName.HasNamedParameters
                ? new ParameterList <T>(Processor).GetNamedParameterList(instance, parameters, member, parameterNames)
                : new ParameterList <T>(Processor).GetParameterList(instance, parameters, member);

            try {
                return(member.Invoke(parameterList));
            }
            catch (TargetInvocationException e) {
                return(TypedValue.MakeInvalid(e.InnerException));
            }
            catch (ValidationException e) {
                return(TypedValue.MakeInvalid(e));
            }
        }
Example #7
0
        public TypedValue Invoke(TypedValue instance, string directMemberName, Tree <Cell> parameters)
        {
            string memberName = directMemberName.Substring(DirectPrefix.Length);

            if (directMemberName == SetUpMethod || directMemberName == TearDownMethod)
            {
                RuntimeMember member = RuntimeType.FindDirectInstance(instance.Value, new IdentifierName(memberName), 0);
                return(member != null
                             ? member.Invoke(new object[] {})
                             : TypedValue.MakeInvalid(new MemberMissingException(instance.Type, memberName, 0)));
            }
            else
            {
                RuntimeMember member = RuntimeType.FindDirectInstance(instance.Value, new IdentifierName(memberName), new[] { typeof(Parse) });
                return(member != null
                             ? member.Invoke(new object[] { parameters.Value })
                             : TypedValue.MakeInvalid(new MemberMissingException(instance.Type, memberName, 1)));
            }
        }
Example #8
0
        public TypedValue Invoke(TypedValue instance, string prefixedMemberName, Tree <Cell> parameters)
        {
            var memberName = prefixedMemberName.Substring(Prefix.Length);
            var type       = Processor.ApplicationUnderTest.FindType("fit.Parse").Type;

            var runtimeType   = Processor.ApplicationUnderTest.FindType("fit.Fixtures.FlowKeywords");
            var runtimeMember = runtimeType.GetConstructor(1);
            var flowKeywords  = runtimeMember.Invoke(new [] { instance.Value });
            var member        = RuntimeType.FindDirectInstance(flowKeywords.Value, new IdentifierName(memberName), new[] { type });

            if (member != null)
            {
                return(member.Invoke(new object[] { parameters.Value }));
            }

            member = RuntimeType.FindDirectInstance(instance.Value, new IdentifierName(memberName), new[] { type });
            return(member != null
                            ? member.Invoke(new object[] { parameters.Value })
                            : TypedValue.MakeInvalid(new MemberMissingException(instance.Type, memberName, 1)));
        }
Example #9
0
        public TypedValue InvokeSpecial(TypedValue instance, MemberName memberName, Tree <Cell> parameters)
        {
            var type = Processor.ApplicationUnderTest.FindType("fit.Parse").Type;

            // lookup Fixture
            foreach (var member in FindMember(instance, memberName, type).Value)
            {
                return(member.Invoke(new object[] { parameters.Value }));
            }

            // lookup FlowKeywords
            var runtimeType   = Processor.ApplicationUnderTest.FindType("fit.Fixtures.FlowKeywords");
            var runtimeMember = runtimeType.GetConstructor(2);
            var flowKeywords  = runtimeMember.Invoke(new[] { instance.Value, Processor });

            foreach (var member in FindMember(flowKeywords, memberName, type).Value)
            {
                return(member.Invoke(new object[] { parameters.Value }));
            }

            return(TypedValue.MakeInvalid(new MemberMissingException(instance.Type, memberName.Name, 1)));
        }
Example #10
0
 public TypedValue InvokeSpecial(TypedValue instance, MemberName memberName, Tree <Cell> parameters)
 {
     return(TypedValue.MakeInvalid(new MemberMissingException(instance.Type, memberName.Name, 1)));
 }