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


C# MemberBinder类代码示例

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


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

示例1: ResolveMembers

            /// <summary>
            /// Returns a list of members that exist on the type.  The ResolvedMember structure indicates both
            /// the name and provides the MemberGroup.
            /// </summary>
            public IList<ResolvedMember/*!*/>/*!*/ ResolveMembers(MemberBinder/*!*/ binder, OldDynamicAction/*!*/ action, Type/*!*/ type) {
                Dictionary<string, ResolvedMember> members = new Dictionary<string, ResolvedMember>();

                foreach (string name in GetCandidateNames(binder, action, type)) {
                    if (members.ContainsKey(name)) {
                        continue;
                    }

                    MemberGroup member = ResolveMember(binder, action, type, name);
                    if (member.Count > 0) {
                        members[name] = new ResolvedMember(name, member);
                    }
                }

                ResolvedMember[] res = new ResolvedMember[members.Count];
                members.Values.CopyTo(res, 0);
                return res;
            }
开发者ID:m4dc4p,项目名称:ironruby,代码行数:22,代码来源:TypeInfo.cs

示例2: DocResolver

        private static MemberGroup/*!*/ DocResolver(MemberBinder/*!*/ binder, Type/*!*/ type) {
            if (_docDescr == null) {
                _docDescr = new DocumentationDescriptor();
            }

            return new MemberGroup(new CustomAttributeTracker(type, "__doc__", _docDescr));
        }
开发者ID:m4dc4p,项目名称:ironruby,代码行数:7,代码来源:TypeInfo.cs

示例3: FormatResolver

        private static MemberGroup/*!*/ FormatResolver(MemberBinder/*!*/ binder, Type/*!*/ type) {
            if (typeof(IFormattable).IsAssignableFrom(type)) {
                return GetInstanceOpsMethod(type, "Format");
            }

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

示例4: InequalityResolver

        /// <summary>
        /// Provides a mapping of IValueEquality.ValueNotEquals to __ne__
        /// </summary>
        private static MemberGroup/*!*/ InequalityResolver(MemberBinder/*!*/ binder, Type/*!*/ type) {
            if (typeof(IValueEquality).IsAssignableFrom(type)) {
                return new MemberGroup(GetEqualityMethods(type, "ValueNotEqualsMethod"));
            }

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

示例5: AllResolver

        private static MemberGroup/*!*/ AllResolver(MemberBinder/*!*/ binder, Type/*!*/ type) {
            // static types are like modules and define __all__.
            if (type.IsAbstract && type.IsSealed) {
                return new MemberGroup(new ExtensionPropertyTracker("__all__", typeof(InstanceOps).GetMethod("Get__all__").MakeGenericMethod(type), null, null, type));
            }

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

示例6: 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

示例7: LengthResolver

        /// <summary>
        /// Provides a resolution for __len__
        /// </summary>
        private static MemberGroup/*!*/ LengthResolver(MemberBinder/*!*/ binder, Type/*!*/ type) {
            if (binder.GetInterfaces(type).Contains(typeof(ICollection))) {
                return GetInstanceOpsMethod(type, "LengthMethod");
            }

            foreach (Type t in binder.GetInterfaces(type)) {
                if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(ICollection<>)) {
                    MethodInfo genMeth = typeof(InstanceOps).GetMethod("GenericLengthMethod");
                    return new MemberGroup(
                        MethodTracker.FromMemberInfo(genMeth.MakeGenericMethod(t.GetGenericArguments()), type)
                    );
                }
            }

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

示例8: ResolveMember

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

                // try mapping __*__ methods to .NET method names
                PythonOperationKind opMap;
                EnsureOperatorTable();

                if (_pythonOperatorTable.TryGetValue(name, out opMap)) {
                    if (IncludeOperatorMethod(type, opMap)) {
                        OperatorMapping opInfo;
                        if (IsReverseOperator(opMap)) {
                            opInfo = OperatorMapping.GetOperatorMapping(opMap & ~PythonOperationKind.Reversed);
                        } else {
                            opInfo = OperatorMapping.GetOperatorMapping(opMap);
                        }

                        if (opInfo != null) {
                            foreach (Type curType in binder.GetContributingTypes(type)) {
                                if (curType == typeof(BigInteger) &&
                                    (opInfo.Operator == PythonOperationKind.Mod ||
                                    opInfo.Operator == PythonOperationKind.RightShift ||
                                    opInfo.Operator == PythonOperationKind.LeftShift ||
                                    opInfo.Operator == PythonOperationKind.Compare ||
                                    opInfo.Operator == PythonOperationKind.Divide)) {
                                    // we override these with our own modulus/power PythonOperationKind which are different from BigInteger.
                                    continue;
                                }

                                Debug.Assert(opInfo.Name != "Equals");

                                MemberGroup res = GetBaseHelperOverloads(type, opInfo.Name, binder.GetMember(curType, opInfo.Name));
                                if (res.Count == 0 && opInfo.AlternateName != null) {
                                    res = binder.GetMember(curType, opInfo.AlternateName);
                                    if (opInfo.AlternateName == "Equals") {
                                        // "Equals" is available as an alternate method name.  Because it's also on object and Python
                                        // doesn't define it on object we need to filter it out.  
                                        res = FilterObjectEquality(res);
                                    } else {
                                        res = GetBaseHelperOverloads(type, opInfo.AlternateName, res);
                                    }
                                }

                                if (res.Count > 0) {
                                    return FilterForwardReverseMethods(name, res, type, opMap);
                                }
                            }
                        }
                    }
                }

                if (name == "__call__") {
                    MemberGroup res = binder.GetMember(type, "Call");
                    if (res.Count > 0) {
                        return res;
                    }
                }

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

示例9: GetCandidateNames

            protected override IEnumerable<string/*!*/>/*!*/ GetCandidateNames(MemberBinder/*!*/ binder, OldDynamicAction/*!*/ action, Type/*!*/ type) {
                EnsureOperatorTable();

                foreach (SymbolId si in _pythonOperatorTable.Keys) {
                    yield return SymbolTable.IdToString(si);
                }

                yield return "__call__";
            }
开发者ID:m4dc4p,项目名称:ironruby,代码行数:9,代码来源:TypeInfo.cs

示例10: 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

示例11: HashResolver

        /// <summary>
        /// Provides a resolution for IValueEquality.GetValueHashCode to __hash__.
        /// </summary>
        private static MemberGroup/*!*/ HashResolver(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 (typeof(IValueEquality).IsAssignableFrom(type) && !type.IsInterface) {
                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:m4dc4p,项目名称:ironruby,代码行数:14,代码来源:TypeInfo.cs

示例12: NextResolver

        /// <summary>
        /// Provides a resolution for next
        /// </summary>
        private static MemberGroup/*!*/ NextResolver(MemberBinder/*!*/ binder, Type/*!*/ type) {
            if (typeof(IEnumerator).IsAssignableFrom(type)) {
                return GetInstanceOpsMethod(type, "NextMethod");
            }

            return MemberGroup.EmptyGroup;
        }
开发者ID:m4dc4p,项目名称:ironruby,代码行数:10,代码来源:TypeInfo.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: StringResolver

        /// <summary>
        /// Provides a resolution for __str__.
        /// </summary>
        private static MemberGroup/*!*/ StringResolver(MemberBinder/*!*/ binder, Type/*!*/ type) {
            if (type != typeof(double) && type != typeof(float)) {
                MethodInfo tostr = type.GetMethod("ToString", Type.EmptyTypes);
                if (tostr != null && tostr.DeclaringType != typeof(object)) {
                    return GetInstanceOpsMethod(type, "ToStringMethod");
                }
            }

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


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