当前位置: 首页>>代码示例>>C#>>正文


C# OverloadResolver.GetGenericInferenceType方法代码示例

本文整理汇总了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);
        }
开发者ID:jschementi,项目名称:iron,代码行数:37,代码来源:TypeInferer.cs

示例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;
            }
开发者ID:rudimk,项目名称:dlr-dotnet,代码行数:11,代码来源:TypeInferer.cs

示例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;
            }
开发者ID:joshholmes,项目名称:ironruby,代码行数:63,代码来源:TypeInferer.cs


注:本文中的Microsoft.Scripting.Actions.Calls.OverloadResolver.GetGenericInferenceType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。