C# Класс Microsoft.Scripting.Actions.Calls.OverloadResolver

Provides binding and overload resolution to .NET methods. MethodBinder's can be used for: generating new AST code for calling a method calling a method via reflection at runtime (not implemented) performing an abstract call MethodBinder's support default arguments, optional arguments, by-ref (in and out), and keyword arguments. Implementation Details: The MethodBinder works by building up a CandidateSet for each number of effective arguments that can be passed to a set of overloads. For example a set of overloads such as: foo(object a, object b, object c) foo(int a, int b) would have 2 target sets - one for 3 parameters and one for 2 parameters. For parameter arrays we fallback and create the appropriately sized CandidateSet on demand. Each CandidateSet consists of a set of MethodCandidate's. Each MethodCandidate knows the flattened parameters that could be received. For example for a function such as: foo(params int[] args) When this method is in a CandidateSet of size 3 the MethodCandidate takes 3 parameters - all of them ints; if it's in a CandidateSet of size 4 it takes 4 parameters. Effectively a MethodCandidate is a simplified view that allows all arguments to be treated as required positional arguments. Each MethodCandidate in turn refers to a MethodTarget. The MethodTarget is composed of a set of ArgBuilder's and a ReturnBuilder which know how to consume the positional arguments and pass them to the appropriate argument of the destination method. This includes routing keyword arguments to the correct position, providing the default values for optional arguments, etc... After binding is finished the MethodCandidates are thrown away and a BindingTarget is returned. The BindingTarget indicates whether the binding was successful and if not any additional information that should be reported to the user about the failed binding. It also exposes the MethodTarget which allows consumers to get the flattened list of required parameters for the call. MethodCandidates are not exposed and are an internal implementation detail of the MethodBinder.
Показать файл Открыть проект Примеры использования класса

Private Properties

Свойство Тип Описание
AddBasicMethodTargets void
AddFailure void
AddSimpleTarget void
AddTarget void
AllowKeywordArgumentSetting bool
BuildCandidateSets void
BuildExpandedTargetSet Microsoft.Scripting.Actions.Calls.CandidateSet
Compare int
CompareEquivalentParameters Candidate
EnsureMatchingNamedArgs List
FindMaxPriority int
GetAccessedCollapsedArgTypes System.Type[]
GetCandidateSet Microsoft.Scripting.Actions.Calls.CandidateSet
GetCollapsedArgumentValue object
GetExpectedArgCounts int[]
GetPreferredCandidate Candidate
GetPreferredParameter Candidate
GetPreferredParameters Candidate
GetRestrictedArgs Microsoft.Scripting.Actions.Calls.RestrictedArguments
GetSplatLimits void
GetSplattedItemExpression System.Linq.Expressions.Expression
GetTemporary System.Linq.Expressions.ParameterExpression
IsBest bool
IsOverloadedOnParameter bool
IsUnsupported bool
MakeAmbiguousBindingTarget BindingTarget
MakeAmbiguousCallError ErrorInfo
MakeBindingTarget BindingTarget
MakeCallFailureError ErrorInfo
MakeFailedBindingTarget BindingTarget
MakeIncorrectArgumentCountError ErrorInfo
MakeInvalidArgumentsError ErrorInfo
MakeNoCallableMethodError ErrorInfo
MakeSuccessfulBindingTarget BindingTarget
MapSpecialParameters System.Collections.BitArray
RestrictArgument System.Dynamic.DynamicMetaObject
SelectBestCandidate Microsoft.Scripting.Actions.Calls.ApplicableCandidate
SelectCandidatesWithConvertibleArgs List
SelectCandidatesWithConvertibleCollapsedArgs List
ToString string
TryConvertArguments bool
TryConvertCollapsedArguments bool

Открытые методы

Метод Описание
CanConvertFrom ( Microsoft.Scripting.Actions.Calls.ParameterWrapper parameter1, Microsoft.Scripting.Actions.Calls.ParameterWrapper parameter2 ) : bool
CanConvertFrom ( Type fromType, DynamicMetaObject fromArgument, Microsoft.Scripting.Actions.Calls.ParameterWrapper toParameter, NarrowingLevel level ) : bool
Convert ( DynamicMetaObject metaObject, Type restrictedType, ParameterInfo info, Type toType ) : Expression
GetActualArguments ( ) : Microsoft.Scripting.Actions.Calls.ActualArguments
GetCollapsedArgsCondition ( ) : Expression
GetDynamicConversion ( Expression value, Type type ) : Expression
GetGenericInferenceType ( DynamicMetaObject dynamicObject ) : Type
MakeInvalidParametersError ( BindingTarget target ) : ErrorInfo
ParametersEquivalent ( Microsoft.Scripting.Actions.Calls.ParameterWrapper parameter1, Microsoft.Scripting.Actions.Calls.ParameterWrapper parameter2 ) : bool
PreferConvert ( Type t1, Type t2 ) : Candidate

Provides ordering for two parameter types if there is no conversion between the two parameter types.

ResolveOverload ( string methodName, IList methods, NarrowingLevel minLevel, NarrowingLevel maxLevel ) : BindingTarget

Resolves a method overload and returns back a BindingTarget. The BindingTarget can then be tested for the success or particular type of failure that prevents the method from being called. If successfully bound the BindingTarget contains a list of argument meta-objects with additional restrictions that ensure the selection of the particular overload.

ResolveOverload ( string methodName, IList methods, NarrowingLevel minLevel, NarrowingLevel maxLevel ) : BindingTarget
SelectBestConversionFor ( DynamicMetaObject arg, Microsoft.Scripting.Actions.Calls.ParameterWrapper candidateOne, Microsoft.Scripting.Actions.Calls.ParameterWrapper candidateTwo, NarrowingLevel level ) : Candidate

Selects the best (of two) candidates for conversion from actualType

Защищенные методы

Метод Описание
AllowMemberInitialization ( OverloadInfo method ) : bool

Checks to see if the language allows named arguments to be bound to instance fields or properties and turned into setters. By default this is only allowed on contructors.

BindToUnexpandedParams ( MethodCandidate candidate ) : bool

Allow to bind an array/dictionary instance or a null reference to params array/dictionary parameter.

CompareEquivalentCandidates ( Microsoft.Scripting.Actions.Calls.ApplicableCandidate one, Microsoft.Scripting.Actions.Calls.ApplicableCandidate two ) : Candidate
CreateActualArguments ( IList namedArgs, IList argNames, int preSplatLimit, int postSplatLimit ) : Microsoft.Scripting.Actions.Calls.ActualArguments

Return null if arguments cannot be constructed and overload resolution should produce an error.

GetByRefArrayExpression ( Expression argumentArrayExpression ) : Expression

Gets an expression that evaluates to the result of GetByRefArray operation.

GetNamedArguments ( IList &namedArgs, IList &argNames ) : void
GetSplattedExpression ( ) : Expression
GetSplattedItem ( int index ) : object
OverloadResolver ( ActionBinder binder ) : System.Linq.Expressions

Приватные методы

Метод Описание
AddBasicMethodTargets ( OverloadInfo method ) : void
AddFailure ( List &failures, Microsoft.Scripting.Actions.Calls.CallFailure failure ) : void
AddSimpleTarget ( MethodCandidate target ) : void
AddTarget ( MethodCandidate target ) : void
AllowKeywordArgumentSetting ( MethodBase method ) : bool
BuildCandidateSets ( IEnumerable methods ) : void
BuildExpandedTargetSet ( int count ) : Microsoft.Scripting.Actions.Calls.CandidateSet
Compare ( int x, int y ) : int
CompareEquivalentParameters ( MethodCandidate one, MethodCandidate two ) : Candidate
EnsureMatchingNamedArgs ( List candidates, List &failures ) : List
FindMaxPriority ( IList abs, int ceiling ) : int
GetAccessedCollapsedArgTypes ( ) : System.Type[]
GetCandidateSet ( ) : Microsoft.Scripting.Actions.Calls.CandidateSet
GetCollapsedArgumentValue ( int collapsedArgIndex ) : object
GetExpectedArgCounts ( ) : int[]
GetPreferredCandidate ( Microsoft.Scripting.Actions.Calls.ApplicableCandidate one, Microsoft.Scripting.Actions.Calls.ApplicableCandidate two, NarrowingLevel level ) : Candidate
GetPreferredParameter ( Microsoft.Scripting.Actions.Calls.ParameterWrapper candidateOne, Microsoft.Scripting.Actions.Calls.ParameterWrapper candidateTwo, DynamicMetaObject arg, NarrowingLevel level ) : Candidate
GetPreferredParameters ( Microsoft.Scripting.Actions.Calls.ApplicableCandidate one, Microsoft.Scripting.Actions.Calls.ApplicableCandidate two, NarrowingLevel level ) : Candidate
GetRestrictedArgs ( Microsoft.Scripting.Actions.Calls.ApplicableCandidate selectedCandidate, IList candidates, int targetSetSize ) : Microsoft.Scripting.Actions.Calls.RestrictedArguments
GetSplatLimits ( int &preSplatLimit, int &postSplatLimit ) : void
GetSplattedItemExpression ( Expression indexExpression ) : Expression

The method is called each time an item of lazily splatted argument is needed.

GetTemporary ( Type type, string name ) : System.Linq.Expressions.ParameterExpression
IsBest ( Microsoft.Scripting.Actions.Calls.ApplicableCandidate candidate, List candidates, NarrowingLevel level ) : bool
IsOverloadedOnParameter ( int argIndex, int argCount, IList overloads ) : bool

Determines whether given overloads are overloaded on index-th parameter (the types of the index-th parameters are the same).

IsUnsupported ( OverloadInfo method ) : bool
MakeAmbiguousBindingTarget ( List result ) : BindingTarget
MakeAmbiguousCallError ( BindingTarget target ) : ErrorInfo
MakeBindingTarget ( Microsoft.Scripting.Actions.Calls.CandidateSet targetSet ) : BindingTarget
MakeCallFailureError ( BindingTarget target ) : ErrorInfo
MakeFailedBindingTarget ( Microsoft.Scripting.Actions.Calls.CallFailure failures ) : BindingTarget
MakeIncorrectArgumentCountError ( BindingTarget target ) : ErrorInfo
MakeInvalidArgumentsError ( ) : ErrorInfo
MakeNoCallableMethodError ( ) : ErrorInfo
MakeSuccessfulBindingTarget ( Microsoft.Scripting.Actions.Calls.ApplicableCandidate result, List potentialCandidates, NarrowingLevel level, Microsoft.Scripting.Actions.Calls.CandidateSet targetSet ) : BindingTarget
MapSpecialParameters ( ParameterMapping mapping ) : BitArray
RestrictArgument ( DynamicMetaObject arg, Microsoft.Scripting.Actions.Calls.ParameterWrapper parameter ) : DynamicMetaObject
SelectBestCandidate ( List candidates, NarrowingLevel level ) : Microsoft.Scripting.Actions.Calls.ApplicableCandidate
SelectCandidatesWithConvertibleArgs ( List candidates, NarrowingLevel level, List &failures ) : List
SelectCandidatesWithConvertibleCollapsedArgs ( List candidates, NarrowingLevel level, List &failures ) : List
ToString ( ) : string
TryConvertArguments ( MethodCandidate candidate, Microsoft.Scripting.Actions.Calls.ArgumentBinding namesBinding, NarrowingLevel narrowingLevel, Microsoft.Scripting.Actions.Calls.CallFailure &failure ) : bool
TryConvertCollapsedArguments ( MethodCandidate candidate, NarrowingLevel narrowingLevel, Microsoft.Scripting.Actions.Calls.CallFailure &failure ) : bool

Описание методов

AllowMemberInitialization() защищенный Метод

Checks to see if the language allows named arguments to be bound to instance fields or properties and turned into setters. By default this is only allowed on contructors.
protected AllowMemberInitialization ( OverloadInfo method ) : bool
method OverloadInfo
Результат bool

BindToUnexpandedParams() защищенный Метод

Allow to bind an array/dictionary instance or a null reference to params array/dictionary parameter.
protected BindToUnexpandedParams ( MethodCandidate candidate ) : bool
candidate MethodCandidate
Результат bool

CanConvertFrom() публичный Метод

public CanConvertFrom ( Microsoft.Scripting.Actions.Calls.ParameterWrapper parameter1, Microsoft.Scripting.Actions.Calls.ParameterWrapper parameter2 ) : bool
parameter1 Microsoft.Scripting.Actions.Calls.ParameterWrapper
parameter2 Microsoft.Scripting.Actions.Calls.ParameterWrapper
Результат bool

CanConvertFrom() публичный Метод

public CanConvertFrom ( Type fromType, DynamicMetaObject fromArgument, Microsoft.Scripting.Actions.Calls.ParameterWrapper toParameter, NarrowingLevel level ) : bool
fromType System.Type
fromArgument System.Dynamic.DynamicMetaObject
toParameter Microsoft.Scripting.Actions.Calls.ParameterWrapper
level NarrowingLevel
Результат bool

CompareEquivalentCandidates() защищенный Метод

protected CompareEquivalentCandidates ( Microsoft.Scripting.Actions.Calls.ApplicableCandidate one, Microsoft.Scripting.Actions.Calls.ApplicableCandidate two ) : Candidate
one Microsoft.Scripting.Actions.Calls.ApplicableCandidate
two Microsoft.Scripting.Actions.Calls.ApplicableCandidate
Результат Candidate

Convert() публичный Метод

public Convert ( DynamicMetaObject metaObject, Type restrictedType, ParameterInfo info, Type toType ) : Expression
metaObject System.Dynamic.DynamicMetaObject
restrictedType System.Type
info System.Reflection.ParameterInfo
toType System.Type
Результат System.Linq.Expressions.Expression

CreateActualArguments() защищенный абстрактный Метод

Return null if arguments cannot be constructed and overload resolution should produce an error.
protected abstract CreateActualArguments ( IList namedArgs, IList argNames, int preSplatLimit, int postSplatLimit ) : Microsoft.Scripting.Actions.Calls.ActualArguments
namedArgs IList
argNames IList
preSplatLimit int
postSplatLimit int
Результат Microsoft.Scripting.Actions.Calls.ActualArguments

GetActualArguments() публичный Метод

public GetActualArguments ( ) : Microsoft.Scripting.Actions.Calls.ActualArguments
Результат Microsoft.Scripting.Actions.Calls.ActualArguments

GetByRefArrayExpression() защищенный Метод

Gets an expression that evaluates to the result of GetByRefArray operation.
protected GetByRefArrayExpression ( Expression argumentArrayExpression ) : Expression
argumentArrayExpression System.Linq.Expressions.Expression
Результат System.Linq.Expressions.Expression

GetCollapsedArgsCondition() публичный Метод

public GetCollapsedArgsCondition ( ) : Expression
Результат System.Linq.Expressions.Expression

GetDynamicConversion() публичный Метод

public GetDynamicConversion ( Expression value, Type type ) : Expression
value System.Linq.Expressions.Expression
type System.Type
Результат System.Linq.Expressions.Expression

GetGenericInferenceType() публичный Метод

public GetGenericInferenceType ( DynamicMetaObject dynamicObject ) : Type
dynamicObject System.Dynamic.DynamicMetaObject
Результат System.Type

GetNamedArguments() защищенный Метод

protected GetNamedArguments ( IList &namedArgs, IList &argNames ) : void
namedArgs IList
argNames IList
Результат void

GetSplattedExpression() защищенный абстрактный Метод

protected abstract GetSplattedExpression ( ) : Expression
Результат System.Linq.Expressions.Expression

GetSplattedItem() защищенный абстрактный Метод

protected abstract GetSplattedItem ( int index ) : object
index int
Результат object

MakeInvalidParametersError() публичный Метод

public MakeInvalidParametersError ( BindingTarget target ) : ErrorInfo
target BindingTarget
Результат ErrorInfo

OverloadResolver() защищенный Метод

protected OverloadResolver ( ActionBinder binder ) : System.Linq.Expressions
binder ActionBinder
Результат System.Linq.Expressions

ParametersEquivalent() публичный Метод

public ParametersEquivalent ( Microsoft.Scripting.Actions.Calls.ParameterWrapper parameter1, Microsoft.Scripting.Actions.Calls.ParameterWrapper parameter2 ) : bool
parameter1 Microsoft.Scripting.Actions.Calls.ParameterWrapper
parameter2 Microsoft.Scripting.Actions.Calls.ParameterWrapper
Результат bool

PreferConvert() публичный Метод

Provides ordering for two parameter types if there is no conversion between the two parameter types.
public PreferConvert ( Type t1, Type t2 ) : Candidate
t1 System.Type
t2 System.Type
Результат Candidate

ResolveOverload() публичный Метод

Resolves a method overload and returns back a BindingTarget. The BindingTarget can then be tested for the success or particular type of failure that prevents the method from being called. If successfully bound the BindingTarget contains a list of argument meta-objects with additional restrictions that ensure the selection of the particular overload.
public ResolveOverload ( string methodName, IList methods, NarrowingLevel minLevel, NarrowingLevel maxLevel ) : BindingTarget
methodName string
methods IList
minLevel NarrowingLevel
maxLevel NarrowingLevel
Результат BindingTarget

ResolveOverload() публичный Метод

public ResolveOverload ( string methodName, IList methods, NarrowingLevel minLevel, NarrowingLevel maxLevel ) : BindingTarget
methodName string
methods IList
minLevel NarrowingLevel
maxLevel NarrowingLevel
Результат BindingTarget

SelectBestConversionFor() публичный Метод

Selects the best (of two) candidates for conversion from actualType
public SelectBestConversionFor ( DynamicMetaObject arg, Microsoft.Scripting.Actions.Calls.ParameterWrapper candidateOne, Microsoft.Scripting.Actions.Calls.ParameterWrapper candidateTwo, NarrowingLevel level ) : Candidate
arg System.Dynamic.DynamicMetaObject
candidateOne Microsoft.Scripting.Actions.Calls.ParameterWrapper
candidateTwo Microsoft.Scripting.Actions.Calls.ParameterWrapper
level NarrowingLevel
Результат Candidate