SelectMethods() public method

Selects the public factory methods for the supplied type.

The ordering of the returned methods is based on the number of parameters of the method. Methods with fewer parameters are returned before methods with more parameters. This means that if a default parameterless factory methods exists, it will be the first one returned.

In case of two factory methods with an equal number of parameters, the ordering is unspecified.

Factory methods that contain parameters of the requested type are skipped in order to avoid circular references.

public SelectMethods ( Type type ) : IEnumerable
type System.Type The type.
return IEnumerable
 public void SelectMethodsFromNullTypeThrows()
 {
     // Fixture setup
     var sut = new FactoryMethodQuery();
     // Exercise system and verify outcome
     Assert.Throws<ArgumentNullException>(() =>
         sut.SelectMethods(null));
     // Teardown
 }
 public void SelectMethodsFromTypeWithParameterOfSameTypeReturnsEmptyResult()
 {
     // Fixture setup
     var type = typeof(TypeWithPseudoFactoryMethod);
     var sut = new FactoryMethodQuery();
     // Exercise system
     var result = sut.SelectMethods(type);
     // Verify outcome
     Assert.False(result.Any());
     // Teardown
 }
 public void SelectMethodsFromTypeWithNoPublicConstructorReturnsCorrectResult()
 {
     // Fixture setup
     var sut = new FactoryMethodQuery();
     var typeWithNoPublicConstructors = typeof(AbstractType);
     // Exercise system
     var result = sut.SelectMethods(typeWithNoPublicConstructors);
     // Verify outcome
     Assert.False(result.Any());
     // Teardown
 }
        public void SelectMethodsFromTypeReturnsCorrectResult(Type type)
        {
            // Fixture setup
            var expectedMethods =
                from mi in type.GetMethods(BindingFlags.Static | BindingFlags.Public)
                where mi.ReturnType == type
                let parameters = mi.GetParameters()
                orderby parameters.Length ascending
                select new StaticMethod(mi) as IMethod;

            var sut = new FactoryMethodQuery();
            // Exercise system
            var result = sut.SelectMethods(type);
            // Verify outcome
            Assert.True(expectedMethods.SequenceEqual(result));
            // Teardown
        }