本文整理汇总了C#中Microsoft.Scripting.Actions.Calls.OverloadResolver.GetGenericInferenceType方法的典型用法代码示例。如果您正苦于以下问题:C# OverloadResolver.GetGenericInferenceType方法的具体用法?C# OverloadResolver.GetGenericInferenceType怎么用?C# OverloadResolver.GetGenericInferenceType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Scripting.Actions.Calls.OverloadResolver
的用法示例。
在下文中一共展示了OverloadResolver.GetGenericInferenceType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetInferedType
/// <summary>
/// Provides generic type inference for a single parameter.
/// </summary>
/// <remarks>
/// For example:
/// M{T}(T x)
/// M{T}(IList{T} x)
/// M{T}(ref T x)
/// M{T}(T[] x)
/// M{T}(ref Dictionary{T,T}[] x)
/// </remarks>
internal static Type GetInferedType(OverloadResolver/*!*/ resolver, Type/*!*/ genericParameter, Type/*!*/ parameterType,
DynamicMetaObject/*!*/ input, Dictionary<Type, Type>/*!*/ binding, Dictionary<DynamicMetaObject, BindingRestrictions>/*!*/ restrictions) {
if (parameterType.IsSubclassOf(typeof(Delegate))) {
// see if we have an invokable object which can be used to infer into this delegate
IInferableInvokable invokeInfer = input as IInferableInvokable;
if (invokeInfer != null) {
InferenceResult inference = invokeInfer.GetInferredType(parameterType, genericParameter);
if (inference != null) {
if (inference.Restrictions != BindingRestrictions.Empty) {
restrictions[input] = inference.Restrictions;
}
binding[genericParameter] = inference.Type;
if (ConstraintsViolated(inference.Type, genericParameter, binding)) {
return null;
}
return inference.Type;
}
}
}
return GetInferedType(genericParameter, parameterType, resolver.GetGenericInferenceType(input), input.LimitType, binding);
}
示例2: GetInferedType
public override Type GetInferedType(OverloadResolver resolver, Type genericParameter, DynamicMetaObject input, Dictionary<Type, Type> prevConstraints, Dictionary<DynamicMetaObject, BindingRestrictions> restrictions) {
Type inputType = resolver.GetGenericInferenceType(input);
if (inputType != null) {
prevConstraints[genericParameter] = inputType;
if (ConstraintsViolated(inputType, genericParameter, prevConstraints)) {
return null;
}
}
return inputType;
}
示例3: GetInferedType
public override Type GetInferedType(OverloadResolver resolver, Type genericParameter, DynamicMetaObject input, Dictionary<Type, Type> prevConstraints, Dictionary<DynamicMetaObject, BindingRestrictions> restrictions) {
Type inputType = resolver.GetGenericInferenceType(input);
if (ParameterType.IsInterface) {
// see if we implement this interface exactly once
Type[] interfaces = inputType.GetInterfaces();
Type targetType = null;
Type genTypeDef = ParameterType.GetGenericTypeDefinition();
foreach (Type ifaceType in interfaces) {
if (ifaceType.IsGenericType && ifaceType.GetGenericTypeDefinition() == genTypeDef) {
if (targetType == null) {
// we may have a match, figure out the type...
targetType = InferGenericType(genericParameter, ifaceType, ParameterType, prevConstraints);
} else {
// multiple interface implementations match
return null;
}
}
}
prevConstraints[genericParameter] = targetType;
return targetType;
} else if (ParameterType.IsSubclassOf(typeof(Delegate))) {
// see if we have an invokable object which can be used to infer into this delegate
IInferableInvokable invokeInfer = input as IInferableInvokable;
if (invokeInfer != null) {
InferenceResult inference = invokeInfer.GetInferredType(ParameterType, genericParameter);
if (inference != null) {
if (inference.Restrictions != BindingRestrictions.Empty) {
restrictions[input] = inference.Restrictions;
}
prevConstraints[genericParameter] = inference.Type;
if (ConstraintsViolated(inference.Type, genericParameter, prevConstraints)) {
return null;
}
return inference.Type;
}
}
}
// see if we're anywhere in our base class hierarchy
Type curType = input.LimitType;
Type genType = ParameterType.GetGenericTypeDefinition();
while (curType != typeof(object)) {
if (curType.IsGenericType) {
if (curType.GetGenericTypeDefinition() == genType) {
// TODO: Merge w/ the interface logic above
Type unboundType = ParameterType;
Type res = InferGenericType(genericParameter, curType, unboundType, prevConstraints);
prevConstraints[genericParameter] = res;
return res;
}
}
curType = curType.BaseType;
}
return null;
}