Esempio n. 1
0
 static bool FindUsesInGenericConstraints(MetadataReader metadata, GenericParameterHandleCollection collection, FindTypeDecoder decoder)
 {
     foreach (var h in collection)
     {
         var gp = metadata.GetGenericParameter(h);
         foreach (var hc in gp.GetConstraints())
         {
             var gc = metadata.GetGenericParameterConstraint(hc);
             if (decoder.GetTypeFromEntity(metadata, gc.Type))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
        internal static bool IsCustomAttributeOfType(EntityHandle customAttributeCtor, MetadataReader metadata, FindTypeDecoder decoder)
        {
            var declaringAttributeType = customAttributeCtor.GetDeclaringType(metadata);

            return(decoder.GetTypeFromEntity(metadata, declaringAttributeType));
        }
Esempio n. 3
0
        static IEnumerable <ISymbol> AnalyzeModule(ITypeDefinition analyzedType, AnalyzerScope scope, PEFile module)
        {
            var metadata   = module.Metadata;
            var typeSystem = scope.ConstructTypeSystem(module);
            var decoder    = new FindTypeDecoder(typeSystem.MainModule, analyzedType);

            //// resolve type refs
            //int rowCount = metadata.GetTableRowCount(TableIndex.TypeRef);
            //BitSet typeReferences = new BitSet(rowCount);
            //for (int row = 0; row < rowCount; row++)
            //{
            //	var h = MetadataTokens.TypeReferenceHandle(row + 1);
            //	typeReferences[row] = decoder.GetTypeFromReference(metadata, h, 0);
            //}

            //// resolve type specs
            //rowCount = metadata.GetTableRowCount(TableIndex.TypeSpec);
            //BitSet typeSpecifications = new BitSet(rowCount);
            //for (int row = 0; row < rowCount; row++)
            //{
            //	var h = MetadataTokens.TypeSpecificationHandle(row + 1);
            //	typeSpecifications[row] = decoder.GetTypeFromSpecification(metadata, default, h, 0);
            //}

            foreach (ISymbol result in FindUsesInAttributes(typeSystem, metadata, decoder, analyzedType))
            {
                yield return(result);
            }

            foreach (var h in metadata.TypeDefinitions)
            {
                var  td    = metadata.GetTypeDefinition(h);
                bool found = decoder.GetTypeFromEntity(metadata, td.GetBaseTypeOrNil());
                foreach (var ih in td.GetInterfaceImplementations())
                {
                    var ii = metadata.GetInterfaceImplementation(ih);
                    found |= decoder.GetTypeFromEntity(metadata, ii.Interface);
                }

                found |= FindUsesInGenericConstraints(metadata, td.GetGenericParameters(), decoder);

                if (found)
                {
                    yield return(typeSystem.MainModule.GetDefinition(h));
                }
            }

            foreach (var h in metadata.MethodDefinitions)
            {
                var  md    = metadata.GetMethodDefinition(h);
                var  msig  = md.DecodeSignature(decoder, default);
                bool found = FindTypeDecoder.AnyInMethodSignature(msig);
                found |= FindUsesInGenericConstraints(metadata, md.GetGenericParameters(), decoder);
                if (found || ScanMethodBody(analyzedType, module, md, decoder))
                {
                    var method = typeSystem.MainModule.GetDefinition(h);
                    yield return(method?.AccessorOwner ?? method);
                }
            }

            foreach (var h in metadata.FieldDefinitions)
            {
                var fd = metadata.GetFieldDefinition(h);
                if (fd.DecodeSignature(decoder, default))
                {
                    yield return(typeSystem.MainModule.GetDefinition(h));
                }
            }

            foreach (var h in metadata.PropertyDefinitions)
            {
                var pd   = metadata.GetPropertyDefinition(h);
                var psig = pd.DecodeSignature(decoder, default);
                if (FindTypeDecoder.AnyInMethodSignature(psig))
                {
                    yield return(typeSystem.MainModule.GetDefinition(h));
                }
            }

            foreach (var h in metadata.EventDefinitions)
            {
                var ed = metadata.GetEventDefinition(h);
                if (decoder.GetTypeFromEntity(metadata, ed.Type))
                {
                    yield return(typeSystem.MainModule.GetDefinition(h));
                }
            }
        }