public static MethodSpecification Returns(this MethodSpecification @this, Func <MethodInfo, TypeSpecification, TypeSpecification> returnSpecification)
        {
            Guard.NotNull(@this, "this");
            Guard.NotNull(returnSpecification, "returnSpecification");

            return(@this.Combine(m =>
            {
                var returnSpec = returnSpecification(m, TypeSpecificationBuilder.Any);
                return returnSpec(m.ReturnType);
            }));
        }
        public static MethodSpecification Parameter(this MethodSpecification @this, Func <MethodInfo, ParameterSpecification, ParameterSpecification> parameterSpecification)
        {
            Guard.NotNull(@this, "this");
            Guard.NotNull(parameterSpecification, "parameterSpecification");

            return(@this.Combine(m =>
            {
                var parameterSpec = parameterSpecification(m, ParameterSpecificationBuilder.Any);
                var outcomes = m.GetParameters().Select(x => parameterSpec(x));
                return outcomes
                .TryFirst(x => x.WasSuccessful)
                .ValueOrDefault(() => outcomes.Combine());
            }));
        }
        public static MethodSpecification GenericArgument(this MethodSpecification @this, Func <MethodInfo, TypeArgumentSpecification, TypeArgumentSpecification> argumentSpecification)
        {
            Guard.NotNull(@this, "this");
            Guard.NotNull(argumentSpecification, "argumentSpecification");

            return(@this.Combine(m =>
            {
                var argSpec = argumentSpecification(m, TypeArgumentSpecificationBuilder.Any);
                var outcomes = m.GetGenericArguments().Select(x => argSpec(x));
                return outcomes
                .TryFirst(x => x.WasSuccessful)
                .ValueOrDefault(() => outcomes.Combine());
            }));
        }
 public static MethodSpecification HasGenericArguments(this MethodSpecification @this, int count)
 {
     Guard.NotNull(@this, "this");
     return(@this.Combine(m => Outcome.FailIf(m.GetGenericArguments().Length != count, String.Format("Did not have {0} generic argument(s).", count))));
 }
 public static MethodSpecification IsClosedGeneric(this MethodSpecification @this)
 {
     Guard.NotNull(@this, "this");
     return(@this.Combine(m => Outcome.FailIf(m.IsGenericMethodDefinition, "Was not closed generic.")));
 }
 public static MethodSpecification IsPublic(this MethodSpecification @this)
 {
     Guard.NotNull(@this, "this");
     return(@this.Combine(m => Outcome.FailIf(!m.IsPublic, "Was not public.")));
 }
 public static MethodSpecification Named(this MethodSpecification @this, string name)
 {
     Guard.NotNull(@this, "this");
     return(@this.Combine(m => Outcome.FailIf(m.Name != name, String.Format("Was not named '{0}'.", name))));
 }
 public static MethodSpecification IsNotExtensionMethod(this MethodSpecification @this)
 {
     Guard.NotNull(@this, "this");
     return(@this.Combine(m => Outcome.FailIf(m.GetParameters().TryElementAt(0).Select(x => x.IsDefined(typeof(ExtensionAttribute), true)).ValueOrDefault(), "Should not be an extension method.")));
 }
 public static MethodSpecification HasParameters(this MethodSpecification @this, int count)
 {
     Guard.NotNull(@this, "this");
     return(@this.Combine(m => Outcome.FailIf(m.GetParameters().Length != count, String.Format("Did not have {0} parameter(s).", count))));
 }