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


C# MemberBinder.GetContributingTypes方法代码示例

本文整理汇总了C#中MemberBinder.GetContributingTypes方法的典型用法代码示例。如果您正苦于以下问题:C# MemberBinder.GetContributingTypes方法的具体用法?C# MemberBinder.GetContributingTypes怎么用?C# MemberBinder.GetContributingTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MemberBinder的用法示例。


在下文中一共展示了MemberBinder.GetContributingTypes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NewResolver

        /// <summary>
        /// Provides a resolution for __new__.  For standard .NET types __new__ resolves to their
        /// constructor.  For Python types they inherit __new__ from their base class.
        /// 
        /// TODO: Can we just always fallback to object.__new__?  If not why not?
        /// </summary>
        private static MemberGroup/*!*/ NewResolver(MemberBinder/*!*/ binder, Type/*!*/ type) {
            if (type.IsSealed && type.IsAbstract) {
                // static types don't have __new__
                return MemberGroup.EmptyGroup;
            }

            bool isPythonType = typeof(IPythonObject).IsAssignableFrom(type);

            // check and see if __new__ has been overridden by the base type.
            foreach (Type t in binder.GetContributingTypes(type)) {
                if (!isPythonType && t == typeof(ObjectOps) && type != typeof(object)) {
                    break;
                }

                MemberInfo[] news = t.GetMember("__new__");
                if (news.Length > 0) {
                    // type has a specific __new__ overload, return that for the constructor
                    return GetExtensionMemberGroup(type, news);
                }
            }

            // type has no Python __new__, just return the .NET constructors if they have
            // a custom new
            ConstructorInfo[] ctors = type.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);// CompilerHelpers.GetConstructors(type, binder.DomainManager.Configuration.PrivateBinding, true);
            ctors = CompilerHelpers.FilterConstructorsToPublicAndProtected(ctors);
            if (!PythonTypeOps.IsDefaultNew(ctors)) {
                return new MemberGroup(ctors);
            }

            // if no ctor w/ parameters are defined, fall back to object.__new__ which
            // will ignore all the extra arguments allowing the user to just override
            // __init__.
            return MemberGroup.EmptyGroup;
        }
开发者ID:m4dc4p,项目名称:ironruby,代码行数:40,代码来源:TypeInfo.cs

示例2: ReprResolver

        /// <summary>
        /// Provides a resolution for __repr__
        /// </summary>
        private static MemberGroup/*!*/ ReprResolver(MemberBinder/*!*/ binder, Type/*!*/ type) {
            // __repr__ for normal .NET types is special, if we're a Python type then
            // we'll use one of the built-in reprs (from object or from the type)
            if (!PythonBinder.IsPythonType(type) &&
                (!type.IsSealed || !type.IsAbstract)) {     // static types don't get __repr__
                // check and see if __repr__ has been overridden by the base type.
                foreach (Type t in binder.GetContributingTypes(type)) {
                    if (t == typeof(ObjectOps) && type != typeof(object)) {
                        break;
                    }

                    if (t.GetMember("__repr__").Length > 0) {
                        // type has a specific __repr__ overload, pick it up normally later
                        return MemberGroup.EmptyGroup;
                    }
                }

                // no override, pick up the default fancy .NET __repr__
                return binder.GetBaseInstanceMethod(type, "FancyRepr");
            }

            return MemberGroup.EmptyGroup;
        }
开发者ID:m4dc4p,项目名称:ironruby,代码行数:26,代码来源:TypeInfo.cs

示例3: TypeOverridesMethod

        /// <summary>
        /// Helper to see if the type explicitly overrides the method.  This ignores members
        /// defined on object.
        /// </summary>
        private static bool TypeOverridesMethod(MemberBinder/*!*/ binder, Type/*!*/  type, string/*!*/  methodName) {
            // check and see if the method has been overridden by the base type.
            foreach (Type t in binder.GetContributingTypes(type)) {
                if (!PythonBinder.IsPythonType(type) && t == typeof(ObjectOps) && type != typeof(object)) {
                    break;
                }

                MemberInfo[] reduce = t.GetMember(methodName);
                if (reduce.Length > 0) {
                    // type has a specific overload
                    return true;
                }
            }
            return false;
        }
开发者ID:m4dc4p,项目名称:ironruby,代码行数:19,代码来源:TypeInfo.cs

示例4: ResolveMember

            public override MemberGroup/*!*/ ResolveMember(MemberBinder/*!*/ binder, OldDynamicAction/*!*/ action, Type/*!*/ type, string/*!*/ name) {
                foreach (Type t in binder.GetContributingTypes(type)) {
                    MemberGroup res = new MemberGroup(ArrayUtils.FindAll(t.GetMember(name, BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy), ProtectedOnly));

                    for (int i = 0; i < res.Count; i++) {
                        MethodTracker meth = res[i] as MethodTracker;                        
                        if (meth == null) {
                            continue;
                        }

                        if (meth.Name == "Finalize" && meth.Method.GetBaseDefinition() == typeof(object).GetMethod("Finalize", BindingFlags.NonPublic | BindingFlags.Instance)) {
                            MemberTracker[] retained = new MemberTracker[res.Count - 1];
                            if (res.Count == 1) {
                                res = MemberGroup.EmptyGroup;
                            } else {
                                for (int j = 0; j < i; j++) {
                                    retained[j] = res[j];
                                }
                                for (int j = i + 1; j < res.Count; j++) {
                                    retained[j - 1] = res[j];
                                }
                                res = new MemberGroup(retained);
                            }
                            break;
                        }
                    }
                    res = FilterSpecialNames(res, name, action);

                    return GetBaseHelperOverloads(PythonTypeOps.GetFinalSystemType(type), name, res);
                }

                return MemberGroup.EmptyGroup;
            }
开发者ID:m4dc4p,项目名称:ironruby,代码行数:33,代码来源:TypeInfo.cs

示例5: GetCandidateNames

 protected override IEnumerable<string/*!*/>/*!*/ GetCandidateNames(MemberBinder/*!*/ binder, OldDynamicAction/*!*/ action, Type/*!*/ type) {
     // these members are visible but only accept derived types.
     foreach (Type t in binder.GetContributingTypes(type)) {
         MemberInfo[] mems = ArrayUtils.FindAll(t.GetMembers(BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic), ProtectedOnly);
         foreach (MemberInfo mi in mems) {
             yield return mi.Name;
         }
     }
 }
开发者ID:m4dc4p,项目名称:ironruby,代码行数:9,代码来源:TypeInfo.cs

示例6: IterResolver

        /// <summary>
        /// Provides a resolution for __iter__
        /// </summary>
        private static MemberGroup/*!*/ IterResolver(MemberBinder/*!*/ binder, Type/*!*/ type) {
            if (type == typeof(string)) {
                // __iter__ is only exposed in 3.0
                if (binder.Binder.Context.PythonOptions.Python30) {
                    return GetInstanceOpsMethod(type, "IterMethodForString");
                }
                return MemberGroup.EmptyGroup;
            }

            if (typeof(Bytes).IsAssignableFrom(type)) {
                // __iter__ is only exposed in 3.0
                if (binder.Binder.Context.PythonOptions.Python30) {
                    return GetInstanceOpsMethod(type, "IterMethodForBytes");
                }
                return MemberGroup.EmptyGroup;
            }

            foreach (Type t in binder.GetContributingTypes(type)) {
                MemberInfo[] news = t.GetMember("__iter__");
                if (news.Length > 0) {
                    // type has a specific __iter__ overload, we'll pick it up later
                    return MemberGroup.EmptyGroup;
                }
            }

            if (!type.GetTypeInfo().IsDefined(typeof(DontMapIEnumerableToIterAttribute), true)) {
                // no special __iter__, use the default.
                if (typeof(IEnumerable<>).IsAssignableFrom(type)) {
                    return GetInstanceOpsMethod(type, "IterMethodForGenericEnumerable");
                } else if (typeof(IEnumerable).IsAssignableFrom(type)) {
                    return GetInstanceOpsMethod(type, "IterMethodForEnumerable");
                } else if (typeof(IEnumerator<>).IsAssignableFrom(type)) {
                    return GetInstanceOpsMethod(type, "IterMethodForGenericEnumerator");
                } else if (typeof(IEnumerator).IsAssignableFrom(type)) {
                    return GetInstanceOpsMethod(type, "IterMethodForEnumerator");
                }
            }
            
            return MemberGroup.EmptyGroup;
        }
开发者ID:Jaykul,项目名称:IronLangs,代码行数:43,代码来源:PythonTypeInfo.cs

示例7: Resolver

            public MemberGroup/*!*/ Resolver(MemberBinder/*!*/ binder, Type/*!*/ type) {
                if (type.IsSealed && type.IsAbstract) {
                    // static types don't have PythonOperationKind
                    return MemberGroup.EmptyGroup;
                }

                foreach (Type t in binder.GetContributingTypes(type)) {
                    if (t == typeof(BigInteger)) continue;

                    MemberGroup res = binder.GetMember(t, "op_Power");
                    if (res.Count > 0) {
                        return FilterForwardReverseMethods(_pythonName, res, type, _op);
                    }

                    res = binder.GetMember(t, "Power");
                    if (res.Count > 0) {
                        return FilterForwardReverseMethods(_pythonName, res, type, _op);
                    }
                }
                return MemberGroup.EmptyGroup;
            }
开发者ID:m4dc4p,项目名称:ironruby,代码行数:21,代码来源:TypeInfo.cs

示例8: HashResolver

        /// <summary>
        /// Provides a resolution for __hash__, first looking for IStructuralEquatable.GetHashCode,
        /// then IValueEquality.GetValueHashCode.
        /// </summary>
        private static MemberGroup/*!*/ HashResolver(MemberBinder/*!*/ binder, Type/*!*/ type) {
#if FEATURE_VALUE_EQUALITY
            if (typeof(IStructuralEquatable).IsAssignableFrom(type) && !type.IsInterface()) {
#else
            if ((typeof(IStructuralEquatable).IsAssignableFrom(type) ||
                 typeof(IValueEquality).IsAssignableFrom(type)) && !type.IsInterface) {
#endif
                // check and see if __hash__ has been overridden by the base type.
                foreach (Type t in binder.GetContributingTypes(type)) {
                    // if it's defined on object, it's not overridden
                    if (t == typeof(ObjectOps) || t == typeof(object)) {
                        break;
                    }

                    MemberInfo[] hash = t.GetMember("__hash__");
                    if (hash.Length > 0) {
                        return MemberGroup.EmptyGroup;
                    }
                }

#if FEATURE_VALUE_EQUALITY
                return GetInstanceOpsMethod(type, "StructuralHashMethod");
#else
                if (typeof(IStructuralEquatable).IsAssignableFrom(type)) {
                    return GetInstanceOpsMethod(type, "StructuralHashMethod");
                }

                if (typeof(IValueEquality).IsAssignableFrom(type)) {
                    return new MemberGroup(typeof(IValueEquality).GetMethod("GetValueHashCode"));
                }
#endif
            }

            // otherwise we'll pick up __hash__ from ObjectOps which will call .NET's .GetHashCode therefore
            // we don't explicitly search to see if the object overrides GetHashCode here.
            return MemberGroup.EmptyGroup;
        }
开发者ID:Jaykul,项目名称:IronLangs,代码行数:41,代码来源:PythonTypeInfo.cs

示例9: FindCastMethod

        /// <summary>
        /// Helper to get the proper typecasting method, according to the following precedence rules:
        /// 
        /// 1. Strongest (most specific) declaring type
        /// 2. Strongest (most specific) parameter type
        /// 3. Type of conversion
        ///     i.  Implicit
        ///     ii. Explicit
        /// 4. Return type (order specified in toTypes)
        /// </summary>
        private static MethodInfo FindCastMethod(MemberBinder/*!*/ binder, Type/*!*/ fromType, List<Type>/*!*/ toTypes) {
            MethodInfo cast = null;
            ParameterInfo[] castParams = null;
            foreach (Type t in binder.GetContributingTypes(fromType)) {
                foreach (string castName in CastNames) {
                    foreach (MemberInfo member in t.GetMember(castName)) {
                        MethodInfo method;
                        ParameterInfo[] methodParams;

                        // Necessary conditions
                        if (member.MemberType != MemberTypes.Method) {
                            continue;
                        }
                        method = (MethodInfo)member;
                        if (!toTypes.Contains(method.ReturnType) ||
                            (methodParams = method.GetParameters()).Length != 1) {
                            continue;
                        }

                        // Precedence rule 1
                        if (cast == null || method.DeclaringType.IsSubclassOf(cast.DeclaringType)) {
                            cast = method;
                            castParams = methodParams;
                            continue;
                        } else if (method.DeclaringType != cast.DeclaringType) {
                            continue;
                        }

                        // Precedence rule 2
                        if (methodParams[0].ParameterType.IsSubclassOf(castParams[0].ParameterType)) {
                            cast = method;
                            castParams = methodParams;
                            continue;
                        } else if (castParams[0].ParameterType != methodParams[0].ParameterType) {
                            continue;
                        }

                        // Precedence rule 3
                        if (method.Name != cast.Name) {
                            if (method.Name == "op_Implicit") {
                                cast = method;
                                castParams = methodParams;
                            }
                            continue;
                        }

                        // Precedence rule 4:
                        foreach (Type toType in toTypes) {
                            if (method.ReturnType == toType) {
                                cast = method;
                                castParams = methodParams;
                            } else if (cast.ReturnType == toType) {
                                break;
                            }
                        }
                    }
                }
            }

            return cast;
        }
开发者ID:teejayvanslyke,项目名称:ironruby,代码行数:71,代码来源:TypeInfo.cs

示例10: GetCandidateNames

 protected override IEnumerable<string/*!*/>/*!*/ GetCandidateNames(MemberBinder/*!*/ binder, MemberRequestKind/*!*/ action, Type/*!*/ type) {
     // these members are visible but only accept derived types.
     foreach (Type t in binder.GetContributingTypes(type)) {
         foreach (MemberInfo mi in t.GetMembers(BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic)) {
             if (ProtectedOnly(mi)) {
                 yield return mi.Name;
             }
         }
     }
 }
开发者ID:Jaykul,项目名称:IronLangs,代码行数:10,代码来源:PythonTypeInfo.cs

示例11: ResolveMember

            public override MemberGroup/*!*/ ResolveMember(MemberBinder/*!*/ binder, MemberRequestKind/*!*/ action, Type/*!*/ type, string/*!*/ name) {
                foreach (Type t in binder.GetContributingTypes(type)) {
                    MemberGroup res = new MemberGroup(
                        t.GetMember(name, BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy)
                        .Where(ProtectedOnly)
                        .ToArray());

                    for (int i = 0; i < res.Count; i++) {
                        MethodTracker meth = res[i] as MethodTracker;                        
                        if (meth == null) {
                            continue;
                        }

                        if (meth.Name == "Finalize" && meth.Method.GetBaseDefinition() == typeof(object).GetMethod("Finalize", BindingFlags.NonPublic | BindingFlags.Instance)) {
                            MemberTracker[] retained = new MemberTracker[res.Count - 1];
                            if (res.Count == 1) {
                                res = MemberGroup.EmptyGroup;
                            } else {
                                for (int j = 0; j < i; j++) {
                                    retained[j] = res[j];
                                }
                                for (int j = i + 1; j < res.Count; j++) {
                                    retained[j - 1] = res[j];
                                }
                                res = new MemberGroup(retained);
                            }
                            break;
                        }
                    }
                    return FilterSpecialNames(res, name, action);
                }

                return MemberGroup.EmptyGroup;
            }
开发者ID:Jaykul,项目名称:IronLangs,代码行数:34,代码来源:PythonTypeInfo.cs

示例12: Resolver

            public MemberGroup/*!*/ Resolver(MemberBinder/*!*/ binder, Type/*!*/ type) {
                if (type.IsSealed() && type.IsAbstract()) {
                    // static types don't have PythonOperationKind
                    return MemberGroup.EmptyGroup;
                }

                foreach (Type t in binder.GetContributingTypes(type)) {
                    MemberGroup res = binder.GetMember(t, _methodName);
                    if (res.Count > 0) {
                        return FilterForwardReverseMethods(_pythonName, res, type, _op);
                    }
                }
                return MemberGroup.EmptyGroup;
            }
开发者ID:Jaykul,项目名称:IronLangs,代码行数:14,代码来源:PythonTypeInfo.cs

示例13: IterResolver

        /// <summary>
        /// Provides a resolution for __iter__
        /// </summary>
        private static MemberGroup/*!*/ IterResolver(MemberBinder/*!*/ binder, Type/*!*/ type) {
            // no __iter__ on string, just __getitem__
            if (type != typeof(string)) {
                if (typeof(System.Collections.IEnumerable).IsAssignableFrom(type)) {
                    foreach (Type t in binder.GetContributingTypes(type)) {
                        MemberInfo[] news = t.GetMember("__iter__");
                        if (news.Length > 0) {
                            // type has a specific __i__ overload, we'll pick it up later
                            return MemberGroup.EmptyGroup;
                        }
                    }

                    // no special __iter__, use the default.
                    return GetInstanceOpsMethod(type, "IterMethod");
                }
            }

            return MemberGroup.EmptyGroup;
        }
开发者ID:m4dc4p,项目名称:ironruby,代码行数:22,代码来源:TypeInfo.cs

示例14: FallbackInequalityResolver

        /// <summary>
        /// Looks for an Equals overload defined on the type and if one is present binds __ne__ to an
        /// InstanceOps helper.
        /// </summary>
        private static MemberGroup/*!*/ FallbackInequalityResolver(MemberBinder/*!*/ binder, Type/*!*/ type) {
            // if object defines __eq__ then we can call the reverse version
            if (IncludeOperatorMethod(type, PythonOperationKind.NotEqual)) {
                foreach (Type curType in binder.GetContributingTypes(type)) {
                    MemberGroup mg = binder.GetMember(curType, "Equals");

                    foreach (MemberTracker mt in mg) {
                        if (mt.MemberType != TrackerTypes.Method || mt.DeclaringType == typeof(object)) {
                            continue;
                        }

                        MethodTracker method = (MethodTracker)mt;
                        if ((method.Method.Attributes & MethodAttributes.NewSlot) != 0) {
                            continue;
                        }

                        ParameterInfo[] pis = method.Method.GetParameters();
                        if (pis.Length == 1) {
                            if (pis[0].ParameterType == typeof(object)) {
                                return new MemberGroup(MethodTracker.FromMemberInfo(typeof(InstanceOps).GetMethod("NotEqualsMethod"), curType));
                            }
                        }
                    }
                }
            }

            return MemberGroup.EmptyGroup;
        }
开发者ID:m4dc4p,项目名称:ironruby,代码行数:32,代码来源:TypeInfo.cs

示例15: HashResolver

        /// <summary>
        /// Provides a resolution for IValueEquality.GetValueHashCode to __hash__.
        /// </summary>
        private static MemberGroup/*!*/ HashResolver(MemberBinder/*!*/ binder, Type/*!*/ type) {
            if (typeof(IValueEquality).IsAssignableFrom(type) && !type.IsInterface) {
                // check and see if __new__ has been overridden by the base type.
                foreach (Type t in binder.GetContributingTypes(type)) {
                    if (t == typeof(ObjectOps) || t == typeof(object)) {
                        break;
                    }

                    MemberInfo[] hash = t.GetMember("__hash__");
                    if (hash.Length > 0) {
                        return MemberGroup.EmptyGroup;
                    }
                }

                return new MemberGroup(typeof(IValueEquality).GetMethod("GetValueHashCode"));
            }

            // otherwise we'll pick up __hash__ from ObjectOps which will call .NET's .GetHashCode therefore
            // we don't explicitly search to see if the object overrides GetHashCode here.
            return MemberGroup.EmptyGroup;
        }
开发者ID:techarch,项目名称:ironruby,代码行数:24,代码来源:TypeInfo.cs


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