Class TemplateMethodQuery
Selects public static methods that has the same parameters of another method, ignoring optional parameters and return type.
Inheritance
Implements
Inherited Members
Namespace: AutoFixture.Kernel
Assembly: AutoFixture.dll
Syntax
public class TemplateMethodQuery : IMethodQuery
Remarks
The main target of this IMethodQuery implementation is to be able to late bind to a method even if it has optional parameters added to it.
The order of the methods are based on the match of parameters types of both methods, favoring the method with exactly same parameters to be returned first.
Constructors
| Improve this Doc View SourceTemplateMethodQuery(MethodInfo)
Initializes a new instance of the TemplateMethodQuery class.
Declaration
public TemplateMethodQuery(MethodInfo template)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodInfo | template | The method info to compare. |
TemplateMethodQuery(MethodInfo, Object)
Initializes a new instance of the TemplateMethodQuery class.
Declaration
public TemplateMethodQuery(MethodInfo template, object owner)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodInfo | template | The method info to compare. |
System.Object | owner | The owner. |
Properties
| Improve this Doc View SourceOwner
The owner instance of the System.Reflection.MethodInfo.
Declaration
public object Owner { get; }
Property Value
Type | Description |
---|---|
System.Object |
Template
The template System.Reflection.MethodInfo to compare.
Declaration
public MethodInfo Template { get; }
Property Value
Type | Description |
---|---|
System.Reflection.MethodInfo |
Methods
| Improve this Doc View SourceSelectMethods(Type)
Selects the methods for the supplied type similar to Template.
Declaration
public IEnumerable<IMethod> SelectMethods(Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IMethod> | All public static methods for |
Remarks
The ordering of the returned methods is based on a score that matches the parameters types of the method with the Template method parameters. Methods with the highest score are returned before.
The score is calculated with the following rules: The methods earns 100 points for each exact match parameter type, it loses 50 points for each hierarchy level down of non-matching parameter type and it loses 1 point for each optional parameter. It also sums the score for the generic type arguments or element type with a 10% weight and will decrease 50 points for the difference between the length of the type arguments array. It also gives 5 points if the type is a class instead of an interface.
In case of two methods with an equal score, the ordering is unspecified.