static bool CanDoOperation <O>(O candidate, string operationName, object[] parameters)
        {
            var member = MemberQuery.GetDirectInstance(candidate,
                                                       new MemberSpecification("Can" + operationName, parameters.Length));

            return(member.Invoke(parameters).GetValue <bool>());
        }
 static void InvokeMemberPattern(string memberPattern, string expectedResult) {
     var processor = Builder.CellProcessor();
     var findMember = new FindMemberPattern { Processor = processor };
     var instance = new TestClass();
     var query = new MemberQuery(new MemberSpecification(new MemberName(memberPattern), 0));
     var member = findMember.FindMember(new TypedValue(instance), query);
     Assert.IsTrue(member.HasValueAs<RuntimeMember>());
     member.GetValueAs<RuntimeMember>().Invoke(new object[] {});
     Assert.AreEqual(expectedResult, instance.Field);
 }
        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));
            }
        }
示例#4
0
        public TypedValue Operate <O>(params object[] parameters) where O : class
        {
            var operationType = typeof(O).Name;
            var operationName = operationType.Substring(0, operationType.IndexOf("Operator"));
            var logging       = new OperationLogging(Memory);

            try {
                logging.Start(operationName);
                logging.LogParameters(parameters);
                var candidate = Operators.FindOperator <O>(parameters);
                var member    = MemberQuery.GetDirectInstance(candidate,
                                                              new MemberSpecification(operationName, parameters.Length));
                var result = member.Invoke(parameters).GetValue <TypedValue>();
                logging.LogResult(candidate, result);
                return(result);
            }
            finally {
                logging.End();
            }
        }
示例#5
0
 public static TypedValue FindMember(TypedValue instance, MemberQuery query)
 {
     return(query.FindMember(instance.Value).TypedValue);
 }
示例#6
0
 public static TypedValue FindMember <T>(this Processor <T> processor, TypedValue instance, MemberQuery query)
 {
     return(processor.Operate <FindMemberOperator <T> >(instance, query));
 }
示例#7
0
 public static TypedValue FindMember(TypedValue instance, MemberQuery query) {
     return query.FindMember(instance.Value).TypedValue;
 }
示例#8
0
 public bool CanFindMember(TypedValue instance, MemberQuery query)
 {
     return(true);
 }