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


C# TypeSymbol.TypeAndAllBaseTypes方法代码示例

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


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

示例1: MemberLookup

        // Looks up a member of given name and arity in a particular type.
        private LookupResult MemberLookup(TypeSymbol type, string name, int arity, bool invoked)
        {
            LookupResult result;

            switch (type.TypeKind) {
                case TypeKind.RefType:
                    return MemberLookup(((RefTypeSymbol)type).ReferencedType, name, arity, invoked);

                case TypeKind.TypeParameter:
                    result = MemberLookupInTypeParameter(type, name, arity, invoked); break;

                case TypeKind.Interface:
                    result = MemberLookupInInterface(type, name, arity, invoked); break;

                case TypeKind.Class:
                case TypeKind.Struct:
                case TypeKind.Enum:
                case TypeKind.Delegate:
                case TypeKind.ArrayType:
                    result = MemberLookupInClass(type, name, arity, invoked); break;

                case TypeKind.Error:
                case TypeKind.PointerType:
                    return LookupResult.Empty;

                case TypeKind.Unknown:
                default:
                    Debug.Fail("Unknown type kind");
                    return LookupResult.Empty;
            }

            // TODO: Diagnose ambiguity problems here, and conflicts between non-method and method? Or is that
            // done in the caller?
            return result;


#if SLOW
            // A member lookup is the process whereby the meaning of a name in the context of
            // a type is determined. A member lookup can occur as part of evaluating a 
            // simple-name or a member-access in an expression. If the 
            // simple-name or member-access occurs as the simple-expression of an 
            // invocation-expression, the member is said to be invoked.

            // If a member is a method or event, or if it is a constant, field or property 
            // of a delegate type, then the member is said to be invocable.

            // Member lookup considers not only the name of a member but also the number of
            // type parameters the member has and whether the member is accessible. For the 
            // purposes of member lookup, generic methods and nested generic types have the 
            // number of type parameters indicated in their respective declarations and all 
            // other members have zero type parameters.

            // A member lookup of a name N with K type parameters in a type T is processed as follows:

            // First, a set of accessible members named N is determined.

            // If T is a type parameter, then the set is the union of the sets of accessible 
            // members named N in each of the types specified as a primary constraint or secondary 
            // constraint for T, along with the set of accessible members named N in object.

            // Otherwise, the set consists of all accessible members named N in T, 
            // including inherited members and the accessible members named N in object. If T is 
            // a constructed type, the set of members is obtained by substituting type arguments 
            // as described in §10.3.2. Members that include an override modifier are excluded 
            // from the set.

            var results = new HashSet<Symbol>();
            var inaccessible = new HashSet<Symbol>();
            var notInvocable = new HashSet<Symbol>();
            var hidden1 = new HashSet<Symbol>();
            var hidden2 = new HashSet<Symbol>();

            var types = new HashSet<TypeSymbol>(type.TypeAndAllBaseTypes());
            types.Add(System_Object);

            foreach (TypeSymbol t in types)
            {
                results.UnionWith(
                    from s in t.GetMembers(name)
                    where !s.IsOverride
                    select s);
            }

            inaccessible.UnionWith(from s in results where !IsMemberAccessible(s) select s);
            results.ExceptWith(inaccessible);

            var badArity = new HashSet<Symbol>();

            // Next, if K is zero, all nested types whose declarations include type parameters are removed. 
            // If K is not zero, all members with a different number of type parameters are removed. 
            // Note that when K is zero, methods having type parameters are not removed, since the 
            // type inference process might be able to infer the type arguments.

            if (arity == 0)
            {
                badArity.UnionWith(from s in results where s.IsNestedType() && ((NamedTypeSymbol)s).Arity != 0 select s);
            }
            else
            {
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:101,代码来源:MemberAccess.cs


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