void HandleOverrides(ImmutableArray <MethodImplementationHandle> immutableArray, MetadataModule module) { foreach (var h in immutableArray) { var methodImpl = module.metadata.GetMethodImplementation(h); CollectNamespacesForTypeReference(module.ResolveType(methodImpl.Type, genericContext)); CollectNamespacesForMemberReference(module.ResolveMethod(methodImpl.MethodBody, genericContext)); CollectNamespacesForMemberReference(module.ResolveMethod(methodImpl.MethodDeclaration, genericContext)); } }
internal IEnumerable <IMethod> GetOverrides(MethodDefinitionHandle method) { var metadata = module.metadata; var td = metadata.GetTypeDefinition(handle); foreach (var implHandle in td.GetMethodImplementations()) { var impl = metadata.GetMethodImplementation(implHandle); if (impl.MethodBody == method) { yield return(module.ResolveMethod(impl.MethodDeclaration, new GenericContext(this.TypeParameters))); } } }
public void Add(CustomAttributeHandleCollection attributes, SymbolKind target) { var metadata = module.metadata; foreach (var handle in attributes) { var attribute = metadata.GetCustomAttribute(handle); // Attribute types shouldn't be generic (and certainly not open), so we don't need a generic context. var ctor = module.ResolveMethod(attribute.Constructor, new GenericContext()); var type = ctor.DeclaringType; if (IgnoreAttribute(type, target)) { continue; } Add(new CustomAttribute(module, ctor, handle)); } }
void CollectNamespaces(IEntity entity, MetadataModule module, CodeMappingInfo mappingInfo = null) { if (entity == null || entity.MetadataToken.IsNil) { return; } if (mappingInfo == null) { mappingInfo = CSharpDecompiler.GetCodeMappingInfo(entity.ParentModule.PEFile, entity.MetadataToken); } switch (entity) { case ITypeDefinition td: namespaces.Add(td.Namespace); HandleAttributes(td.GetAttributes()); HandleTypeParameters(td.TypeParameters); foreach (var baseType in td.DirectBaseTypes) { CollectNamespacesForTypeReference(baseType); } foreach (var nestedType in td.NestedTypes) { CollectNamespaces(nestedType, module, mappingInfo); } foreach (var field in td.Fields) { CollectNamespaces(field, module, mappingInfo); } foreach (var property in td.Properties) { CollectNamespaces(property, module, mappingInfo); } foreach (var @event in td.Events) { CollectNamespaces(@event, module, mappingInfo); } foreach (var method in td.Methods) { CollectNamespaces(method, module, mappingInfo); } break; case IField field: HandleAttributes(field.GetAttributes()); CollectNamespacesForTypeReference(field.ReturnType); break; case IMethod method: var reader = module.PEFile.Reader; var parts = mappingInfo.GetMethodParts((MethodDefinitionHandle)method.MetadataToken).ToList(); foreach (var part in parts) { var partMethod = module.ResolveMethod(part, genericContext); HandleAttributes(partMethod.GetAttributes()); HandleAttributes(partMethod.GetReturnTypeAttributes()); CollectNamespacesForTypeReference(partMethod.ReturnType); foreach (var param in partMethod.Parameters) { HandleAttributes(param.GetAttributes()); CollectNamespacesForTypeReference(param.Type); } HandleTypeParameters(partMethod.TypeParameters); HandleOverrides(part.GetMethodImplementations(module.metadata), module); var methodDef = module.metadata.GetMethodDefinition(part); if (method.HasBody) { MethodBodyBlock body; try { body = reader.GetMethodBody(methodDef.RelativeVirtualAddress); } catch (BadImageFormatException) { continue; } CollectNamespacesFromMethodBody(body, module); } } break; case IProperty property: HandleAttributes(property.GetAttributes()); CollectNamespaces(property.Getter, module, mappingInfo); CollectNamespaces(property.Setter, module, mappingInfo); break; case IEvent @event: HandleAttributes(@event.GetAttributes()); CollectNamespaces(@event.AddAccessor, module, mappingInfo); CollectNamespaces(@event.RemoveAccessor, module, mappingInfo); break; } }