Beispiel #1
0
        internal override Symbol GetSymbolForMemberRef(MemberReferenceHandle memberRef, TypeSymbol scope = null, bool methodsOnly = false)
        {
            TypeSymbol targetTypeSymbol = GetMemberRefTypeSymbol(memberRef);

            if ((object)scope != null)
            {
                Debug.Assert(scope.Kind == SymbolKind.NamedType || scope.Kind == SymbolKind.ErrorType);

                // We only want to consider members that are at or above "scope" in the type hierarchy.
                HashSet <DiagnosticInfo> useSiteDiagnostics = null;
                if (scope != targetTypeSymbol &&
                    !(targetTypeSymbol.IsInterfaceType()
                        ? scope.AllInterfacesNoUseSiteDiagnostics.Contains((NamedTypeSymbol)targetTypeSymbol)
                        : scope.IsDerivedFrom(targetTypeSymbol, TypeCompareKind.ConsiderEverything, useSiteDiagnostics: ref useSiteDiagnostics)))
                {
                    return(null);
                }
            }

            // We're going to use a special decoder that can generate usable symbols for type parameters without full context.
            // (We're not just using a different type - we're also changing the type context.)
            var memberRefDecoder = new MemberRefMetadataDecoder(moduleSymbol, targetTypeSymbol);

            return(memberRefDecoder.FindMember(targetTypeSymbol, memberRef, methodsOnly));
        }
Beispiel #2
0
        internal override Symbol GetSymbolForMemberRef(
            MemberReferenceHandle memberRef,
            TypeSymbol scope = null,
            bool methodsOnly = false
            )
        {
            TypeSymbol targetTypeSymbol = GetMemberRefTypeSymbol(memberRef);

            if (targetTypeSymbol is null)
            {
                return(null);
            }

            Debug.Assert(!targetTypeSymbol.IsTupleType);

            if ((object)scope != null)
            {
                Debug.Assert(
                    scope.Kind == SymbolKind.NamedType || scope.Kind == SymbolKind.ErrorType
                    );

                // We only want to consider members that are at or above "scope" in the type hierarchy.
                var discardedUseSiteInfo = CompoundUseSiteInfo <AssemblySymbol> .Discarded;
                if (
                    !TypeSymbol.Equals(scope, targetTypeSymbol, TypeCompareKind.ConsiderEverything2) &&
                    !(
                        targetTypeSymbol.IsInterfaceType()
                          ? scope.AllInterfacesNoUseSiteDiagnostics.IndexOf(
                            (NamedTypeSymbol)targetTypeSymbol,
                            0,
                            SymbolEqualityComparer.CLRSignature
                            ) != -1
                          : scope.IsDerivedFrom(
                            targetTypeSymbol,
                            TypeCompareKind.CLRSignatureCompareOptions,
                            useSiteInfo: ref discardedUseSiteInfo
                            )
                        )
                    )
                {
                    return(null);
                }
            }

            if (!targetTypeSymbol.IsTupleType)
            {
                targetTypeSymbol = TupleTypeDecoder.DecodeTupleTypesIfApplicable(
                    targetTypeSymbol,
                    elementNames: default
                    );
            }

            // We're going to use a special decoder that can generate usable symbols for type parameters without full context.
            // (We're not just using a different type - we're also changing the type context.)
            var memberRefDecoder = new MemberRefMetadataDecoder(moduleSymbol, targetTypeSymbol);

            return(memberRefDecoder.FindMember(targetTypeSymbol, memberRef, methodsOnly));
        }