Search Results for

    Show / Hide Table of Contents

    Class Binding

    Represents the type parameters and argument conversions needed to invoke a method.

    Inheritance
    Object
    Binding
    Inherited Members
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Object.ReferenceEquals(Object, Object)
    Namespace: Microsoft.ML.Probabilistic.Compiler.Reflection
    Assembly: Microsoft.ML.Probabilistic.Compiler.dll
    Syntax
    public class Binding
    Remarks

    Given a generic method definition and a list of arguments, a Binding represents the additional information needed to invoke the method with those arguments. Specifically, it stores a list of type parameters (possibly empty if the method is not generic) and a list of conversions, one for each argument. Note that Bindings are not unique, e.g. a type parameter might be instantiated in several different ways, yet still compatible with the given arguments. Each of these choices is a different Binding.

    This class allows you to find the Binding which is 'best' in the sense of being the most specific. The < operator can be used to compare the specificity of Bindings.

    Constructors

    Binding(Binding)

    Copy constructor.

    Declaration
    public Binding(Binding info)
    Parameters
    Type Name Description
    Binding info

    Binding(MethodBase)

    Creare an empty Binding to a given method.

    Declaration
    public Binding(MethodBase method)
    Parameters
    Type Name Description
    MethodBase method
    Remarks

    The conversions are all set to null.

    Fields

    Conversions

    The conversion inferred for each method parameter position.

    Declaration
    public readonly Conversion[] Conversions
    Field Value
    Type Description
    Conversion[]

    Depth

    Array indexing depth needed to obtain a match.

    Declaration
    public uint Depth
    Field Value
    Type Description
    UInt32

    Types

    The type inferred for each type parameter.

    Declaration
    public readonly Dictionary<Type, Type> Types
    Field Value
    Type Description
    Dictionary<Type, Type>
    Remarks

    All entries are non-null. A missing entry indicates an unconstrained parameter.

    Methods

    ApplyTypeConstraints(Binding, IList<Exception>, ICollection<Type>)

    Expand a binding via type constraints.

    Declaration
    public static IEnumerator<Binding> ApplyTypeConstraints(Binding binding, IList<Exception> errors, ICollection<Type> doneParams = null)
    Parameters
    Type Name Description
    Binding binding

    The binding to expand

    IList<Exception> errors

    A list which collects binding errors.

    ICollection<Type> doneParams

    The set of parameters already processed.

    Returns
    Type Description
    IEnumerator<Binding>

    A stream of Bindings which satisfy the constraints on typeParams[pos] and above.

    ApplyTypeConstraints(MethodBase, IEnumerator<Binding>, IList<Exception>)

    Filter a stream of bindings via type constraints.

    Declaration
    public static IEnumerator<Binding> ApplyTypeConstraints(MethodBase method, IEnumerator<Binding> iter, IList<Exception> errors)
    Parameters
    Type Name Description
    MethodBase method

    A generic method which may have type constraints.

    IEnumerator<Binding> iter

    A stream of Bindings.

    IList<Exception> errors

    A list which collects binding errors.

    Returns
    Type Description
    IEnumerator<Binding>

    A substream of Bindings which all satisfy the type constraints. Type parameters which were previously unknown may be filled in by the type constraints, possibly in multiple ways. Thus a single Binding from iter with an unknown type parameter may expand into many new Bindings, differing only in the instantiation of that parameter. Known type parameters are left unchanged.

    ApplyTypeConstraints(Type, Binding, IList<Exception>)

    Declaration
    public static IEnumerator<Binding> ApplyTypeConstraints(Type typeParam, Binding binding, IList<Exception> errors)
    Parameters
    Type Name Description
    Type typeParam
    Binding binding
    IList<Exception> errors
    Returns
    Type Description
    IEnumerator<Binding>

    ApplyTypeConstraints(Type, Type[], Binding, IList<Exception>, Int32)

    Expand a binding via type constraints.

    Declaration
    public static IEnumerator<Binding> ApplyTypeConstraints(Type actual, Type[] constraints, Binding binding, IList<Exception> errors, int start)
    Parameters
    Type Name Description
    Type actual

    The type that needs to satisfy the constraints.

    Type[] constraints

    The constraints on the type parameter at binding.Types[pos].

    Binding binding

    Any binding.

    IList<Exception> errors

    A list which collects binding errors.

    Int32 start

    The index of the first constraint to process.

    Returns
    Type Description
    IEnumerator<Binding>

    A stream of Bindings which satisfy constraints[start] and higher.

    Bind(MethodBase)

    Specialize a method on the inferred type parameters.

    Declaration
    public MethodBase Bind(MethodBase method)
    Parameters
    Type Name Description
    MethodBase method

    A non-null generic or non-generic method.

    Returns
    Type Description
    MethodBase

    A method with all type parameters of that method filled in. Type parameters of an enclosing type will not be filled in.

    Remarks

    Unknown type parameters are replaced with System.Object.

    Bind(Type)

    Fill in some type parameters.

    Declaration
    public Type Bind(Type type)
    Parameters
    Type Name Description
    Type type

    A type which may have generic parameters.

    Returns
    Type Description
    Type

    A type with possibly fewer generic parameters.

    ConvertAll(Object[])

    Apply the conversions to a set of arguments.

    Declaration
    public void ConvertAll(object[] args)
    Parameters
    Type Name Description
    Object[] args

    An array of length Conversions.Length. Modified to contain the converted values.

    ForEachTypeParameter(Type, Action<Type>)

    Perform an action for each type parameter inside a type.

    Declaration
    public static void ForEachTypeParameter(Type type, Action<Type> action)
    Parameters
    Type Name Description
    Type type
    Action<Type> action

    GetBestBinding(MethodBase, Type[], ConversionOptions, out Exception)

    Find the most specific Binding for a generic method.

    Declaration
    public static Binding GetBestBinding(MethodBase method, Type[] actuals, ConversionOptions conversionOptions, out Exception exception)
    Parameters
    Type Name Description
    MethodBase method
    Type[] actuals

    Types from which to infer type parameters. actuals.Length == number of method parameters. actuals[i] may be null to allow any type, or typeof(Nullable) to mean "any nullable type".

    ConversionOptions conversionOptions

    Specifies which conversions are allowed.

    Exception exception

    Exception created on failure

    Returns
    Type Description
    Binding

    null if binding fails.

    InferGenericParameters(MethodBase, Type[], ConversionOptions, IList<Exception>)

    Infer type parameters for a method call.

    Declaration
    public static IEnumerator<Binding> InferGenericParameters(MethodBase method, Type[] actuals, ConversionOptions conversionOptions, IList<Exception> errors)
    Parameters
    Type Name Description
    MethodBase method
    Type[] actuals

    Types from which to infer type parameters. actuals.Length == number of method parameters. actuals[i] may be null to allow any type, or typeof(Nullable) to mean "any nullable type".

    ConversionOptions conversionOptions

    Specifies which conversions are allowed

    IList<Exception> errors

    A list which collects binding errors.

    Returns
    Type Description
    IEnumerator<Binding>

    An iterator which yields all possible bindings.

    Remarks

    Because it considers all possible bindings for each argument, this function can infer type parameters in cases where the C# 2.0 specification (sec 20.6.4) cannot.

    InferGenericParameters(Type, Type, Binding, IList<Exception>, Int32, Boolean, ConversionOptions)

    Infer type parameter bindings.

    Declaration
    public static IEnumerator<Binding> InferGenericParameters(Type formal, Type actual, Binding binding, IList<Exception> errors, int position, bool allowSubtype, ConversionOptions conversionOptions)
    Parameters
    Type Name Description
    Type formal

    The type with parameters to infer.

    Type actual

    A type from which to infer parameters. May be null to allow any type, or typeof(Nullable) to mean "any nullable type". May itself contain type parameters.

    Binding binding

    Known bindings, which are taken as fixed. Conversions[position] must be null.

    IList<Exception> errors

    A list which collects binding errors.

    Int32 position

    If formal corresponds to a method parameter type, this is the index of the method parameter. Otherwise it is -1 and no conversions are allowed.

    Boolean allowSubtype

    If true, actual can be a subtype of formal (implicit subtype conversions are allowed).

    ConversionOptions conversionOptions

    Specifies which conversions are allowed.

    Returns
    Type Description
    IEnumerator<Binding>

    A stream of all possible bindings which match formal to actual, including conversions.

    Remarks

    Each element of the stream is the same object as binding, but modified to (possibly) include more bindings. binding is returned to its original state at the end of the stream.

    If formal has no type parameters, then at most one Binding is returned.

    InferGenericParameters(Type[], Type[], Binding, IList<Exception>, Int32, Int32, Boolean, Func<Int32, Boolean>, ConversionOptions)

    Infer remaining type parameters for a method call or generic type.

    Declaration
    public static IEnumerator<Binding> InferGenericParameters(Type[] formals, Type[] actuals, Binding binding, IList<Exception> errors, int start, int position, bool isMethodCall, Func<int, bool> allowSubtype, ConversionOptions conversionOptions)
    Parameters
    Type Name Description
    Type[] formals

    Types with parameters to infer.

    Type[] actuals

    The corresponding types from which to infer parameters. actuals.Length == formals.Length. actuals[i] may be null to allow any type, or typeof(Nullable) to mean "any nullable type".

    Binding binding

    The partial binding inferred from actuals[i < start]. Will be mutated and returned as elements of the stream.

    IList<Exception> errors

    A list which collects binding errors.

    Int32 start

    The index into the formals array to begin processing.

    Int32 position

    The index into binding.Conversions to place the conversion. If -1, only null conversions are allowed. Ignored if isMethodCall is true.

    Boolean isMethodCall

    True if formals correspond to method parameters. position is always taken equal to start.

    Func<Int32, Boolean> allowSubtype

    True if implicit subtype conversions are allowed for type i.

    ConversionOptions conversionOptions

    Specifies which conversions are allowed.

    Returns
    Type Description
    IEnumerator<Binding>

    A stream of all possible bindings which match formals[i] to actuals[i], for all i >= start, including conversions.

    Remarks

    Each element of the stream is the same object as binding, but modified to (possibly) include more bindings. binding is returned to its original state at the end of the stream.

    IntersectTypes(Type, Type)

    Get a type which is the most specific of the input types.

    Declaration
    public static Type IntersectTypes(Type t1, Type t2)
    Parameters
    Type Name Description
    Type t1
    Type t2
    Returns
    Type Description
    Type

    PositionString(Int32)

    Declaration
    protected static string PositionString(int position)
    Parameters
    Type Name Description
    Int32 position
    Returns
    Type Description
    String

    ReplaceTypeParameters(Type, IReadOnlyDictionary<Type, Type>)

    Replace type parameters in a generic type.

    Declaration
    public static Type ReplaceTypeParameters(Type type, IReadOnlyDictionary<Type, Type> typeMap)
    Parameters
    Type Name Description
    Type type

    A type which may have generic parameters.

    IReadOnlyDictionary<Type, Type> typeMap

    A dictionary for mapping types

    Returns
    Type Description
    Type

    A type with possibly fewer generic parameters.

    SetTo(Binding)

    Declaration
    public void SetTo(Binding info)
    Parameters
    Type Name Description
    Binding info

    ToString()

    Declaration
    public override string ToString()
    Returns
    Type Description
    String
    Overrides
    Object.ToString()

    TypesAssignableFrom(Type, Boolean)

    All base classes and interfaces of a given type.

    Declaration
    public static IEnumerable<Type> TypesAssignableFrom(Type type, bool includeIList = true)
    Parameters
    Type Name Description
    Type type

    Any non-null type. May be a type parameter.

    Boolean includeIList

    If true, include IList when type is an array.

    Returns
    Type Description
    IEnumerable<Type>

    All base classes and interfaces of type, most specific types first.

    Operators

    GreaterThan(Binding, Binding)

    Declaration
    public static bool operator>(Binding a, Binding b)
    Parameters
    Type Name Description
    Binding a
    Binding b
    Returns
    Type Description
    Boolean

    LessThan(Binding, Binding)

    True if A is more specific than B.

    Declaration
    public static bool operator <(Binding a, Binding b)
    Parameters
    Type Name Description
    Binding a
    Binding b
    Returns
    Type Description
    Boolean

    True if A is more specific than B.

    In This Article
    Back to top Copyright © .NET Foundation. All rights reserved.