Exemple #1
0
        public bool Parse(InvokeMemberBinder binder, object[] args)
        {
            var memberName = binder.Name;

            if (!memberName.StartsWith("With") || memberName == "With")
            {
                return(false);
            }

            argumentStore.Set(new MemberNameAndValue(memberName.Replace("With", ""), args[0]));
            return(true);
        }
Exemple #2
0
        private void ParseNamedArgumentValues(CallInfo callInfo, object[] args)
        {
            if (!callInfo.ArgumentNames.Any())
            {
                throw new ArgumentException("No names were specified for the values provided. When using the named arguments (With()) syntax, you should specify the items to be set as argument names, such as With(customerId: customerId).");
            }

            if (callInfo.ArgumentNames.Count() != args.Length)
            {
                throw new ArgumentException("One or more arguments are missing a name. Names should be specified with C# named argument syntax, e.g. With(customerId: customerId).");
            }

            var argumentIndex = 0;

            foreach (var argumentName in callInfo.ArgumentNames.Select(ToCamelCase))
            {
                argumentStore.Set(new MemberNameAndValue(argumentName, args[argumentIndex++]));
            }
        }