Class MethodReference
Used to look up a method by its declaring type, its name, and its type parameters (if any).
Inherited Members
Namespace: Microsoft.ML.Probabilistic.Compiler.Transforms
Assembly: Microsoft.ML.Probabilistic.Compiler.dll
Syntax
public class MethodReference
Constructors
MethodReference(Type, String, Type[])
Construct a method reference from a name and optional types.
Declaration
public MethodReference(Type type, string methodName, params Type[] parameterTypes)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type providing the method. |
String | methodName | The name must specify the number of generic type parameters via the syntax |
Type[] | parameterTypes | An array of types, which may contain null as a wildcard. |
Remarks
If the method is generic with n
type parameters, then the first n
parameterTypes are interpreted
as type arguments. These can be null to allow arbitrary type arguments.
Examples:
-
new MethodReference(typeof(Array),"Copy",typeof(Array),typeof(Array),typeof(Int32))
This selects the first overload of the non-generic method Copy(Array, Array, Int32).
-
new MethodReference(typeof(Array),"Copy",null,null,typeof(Int32))
This selects the same method as above, since the number of parameters and the type of the third parameter disambiguate the overload.
-
new MethodReference(typeof(Array),"Find")
This throws an exception since Find<T>(T[], Predicate<T>) is a generic method only.
-
new MethodReference(typeof(Array),"Find<>")
This selects the generic method Find<T>(T[], Predicate<T>), without specifying any type arguments or parameter types. This method is not overloaded so no disambiguation via parameter types is needed.
-
new MethodReference(typeof(Array),"Find<>",null)
This is equivalent to the above. Adding two more nulls (corresponding to the two parameters of Find) would also be equivalent.
-
new MethodReference(typeof(Array),"Find<>",typeof(int))
This selects the generic method Find<T>(T[], Predicate<T>), with type argument set to
int
. No parameter types are specified. This method is not overloaded so no disambiguation via parameter types is needed. -
new MethodReference(typeof(Array),"FindIndex<>",typeof(int),typeof(int[]),typeof(Predicate<int>))
This selects the first overload of the generic method FindIndex<T>(T[], Predicate<T>), with type argument set to
int
. -
new MethodReference(typeof(Array),"FindIndex<>",typeof(int),null,null)
This selects the same method as above, since the number of parameters (two) disambiguates the overload.
-
new MethodReference(typeof(Array),"FindIndex<>",null,null,null)
This selects the first overload of the generic method FindIndex<T>(T[], Predicate<T>), without specializing on a type argument.
Fields
LastMatchException
Declaration
protected Exception LastMatchException
Field Value
Type | Description |
---|---|
Exception |
MethodName
Declaration
public string MethodName
Field Value
Type | Description |
---|---|
String |
ParameterTypes
Declaration
public Type[] ParameterTypes
Field Value
Type | Description |
---|---|
Type[] |
Type
Declaration
public Type Type
Field Value
Type | Description |
---|---|
Type |
TypeArguments
Declaration
public Type[] TypeArguments
Field Value
Type | Description |
---|---|
Type[] |
TypeParameterCount
Declaration
public int TypeParameterCount
Field Value
Type | Description |
---|---|
Int32 |
Methods
FromFactorAttribute(FactorMethodAttribute)
Declaration
public static MethodReference FromFactorAttribute(FactorMethodAttribute attr)
Parameters
Type | Name | Description |
---|---|---|
FactorMethodAttribute | attr |
Returns
Type | Description |
---|---|
MethodReference |
GetAmbiguousMatchString(MethodInfo[])
Declaration
protected string GetAmbiguousMatchString(MethodInfo[] methods)
Parameters
Type | Name | Description |
---|---|---|
MethodInfo[] | methods |
Returns
Type | Description |
---|---|
String |
GetMethodInfo()
Convert the MethodReference into a concrete MethodInfo.
Declaration
public MethodInfo GetMethodInfo()
Returns
Type | Description |
---|---|
MethodInfo |
Exceptions
Type | Condition |
---|---|
MissingMethodException | No methods of |
AmbiguousMatchException | More than one method matches (due to wildcards in the MethodReference). |
ArgumentException | A type argument does not satisfy the constraints of the generic method definition. |
MakeGenericMethod(MethodInfo, Type[])
Same as MakeGenericMethod(Type[]), but allows null
as a wildcard.
Declaration
public static MethodInfo MakeGenericMethod(MethodInfo method, Type[] typeArguments)
Parameters
Type | Name | Description |
---|---|---|
MethodInfo | method | A generic method. |
Type[] | typeArguments | An array of types, some of which may be null. |
Returns
Type | Description |
---|---|
MethodInfo | A method with the non-null type arguments filled in. |
MatchesMethod(MethodInfo)
Test if a MethodInfo satisfies the constraints of a MethodReference.
Declaration
public bool MatchesMethod(MethodInfo method)
Parameters
Type | Name | Description |
---|---|---|
MethodInfo | method | A method to test. |
Returns
Type | Description |
---|---|
Boolean | True if the method satisfies the constraints. |
Parse(String)
Declaration
public static MethodReference Parse(string s)
Parameters
Type | Name | Description |
---|---|---|
String | s |
Returns
Type | Description |
---|---|
MethodReference |
Parse(String, String)
Declaration
public static MethodReference Parse(string s, string namespaceName)
Parameters
Type | Name | Description |
---|---|---|
String | s | |
String | namespaceName |
Returns
Type | Description |
---|---|
MethodReference |
ParseGenericMethodName(String, out Int32)
Parse a method name of the form fun
or fun<>
or fun<,>
, etc.
Declaration
public static string ParseGenericMethodName(string methodName, out int typeParameterCount)
Parameters
Type | Name | Description |
---|---|---|
String | methodName | |
Int32 | typeParameterCount |
Returns
Type | Description |
---|---|
String | The raw method name with generic suffix removed. |
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String |