1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System; 6 using System.Collections.Generic; 7 8 using Internal.TypeSystem; 9 using ILCompiler.DependencyAnalysis; 10 11 using Debug = System.Diagnostics.Debug; 12 13 namespace ILCompiler 14 { 15 public class EmptyMetadataManager : MetadataManager 16 { 17 public override bool SupportsReflection => false; 18 EmptyMetadataManager(CompilerTypeSystemContext typeSystemContext)19 public EmptyMetadataManager(CompilerTypeSystemContext typeSystemContext) 20 : base(typeSystemContext, new FullyBlockedMetadataPolicy()) 21 { 22 } 23 GetCompilationModulesWithMetadata()24 public override IEnumerable<ModuleDesc> GetCompilationModulesWithMetadata() 25 { 26 return Array.Empty<ModuleDesc>(); 27 } 28 GetMetadataCategory(FieldDesc field)29 protected override MetadataCategory GetMetadataCategory(FieldDesc field) 30 { 31 return MetadataCategory.None; 32 } 33 GetMetadataCategory(MethodDesc method)34 protected override MetadataCategory GetMetadataCategory(MethodDesc method) 35 { 36 return MetadataCategory.None; 37 } 38 GetMetadataCategory(TypeDesc type)39 protected override MetadataCategory GetMetadataCategory(TypeDesc type) 40 { 41 return MetadataCategory.None; 42 } 43 ComputeMetadata(NodeFactory factory, out byte[] metadataBlob, out List<MetadataMapping<MetadataType>> typeMappings, out List<MetadataMapping<MethodDesc>> methodMappings, out List<MetadataMapping<FieldDesc>> fieldMappings, out List<MetadataMapping<MethodDesc>> stackTraceMapping)44 protected override void ComputeMetadata(NodeFactory factory, 45 out byte[] metadataBlob, 46 out List<MetadataMapping<MetadataType>> typeMappings, 47 out List<MetadataMapping<MethodDesc>> methodMappings, 48 out List<MetadataMapping<FieldDesc>> fieldMappings, 49 out List<MetadataMapping<MethodDesc>> stackTraceMapping) 50 { 51 metadataBlob = Array.Empty<byte>(); 52 53 typeMappings = new List<MetadataMapping<MetadataType>>(); 54 methodMappings = new List<MetadataMapping<MethodDesc>>(); 55 fieldMappings = new List<MetadataMapping<FieldDesc>>(); 56 stackTraceMapping = new List<MetadataMapping<MethodDesc>>(); 57 } 58 59 /// <summary> 60 /// Is there a reflection invoke stub for a method that is invokable? 61 /// </summary> HasReflectionInvokeStubForInvokableMethod(MethodDesc method)62 public override bool HasReflectionInvokeStubForInvokableMethod(MethodDesc method) 63 { 64 Debug.Assert(IsReflectionInvokable(method)); 65 return false; 66 } 67 68 /// <summary> 69 /// Gets a stub that can be used to reflection-invoke a method with a given signature. 70 /// </summary> GetCanonicalReflectionInvokeStub(MethodDesc method)71 public override MethodDesc GetCanonicalReflectionInvokeStub(MethodDesc method) 72 { 73 return null; 74 } 75 WillUseMetadataTokenToReferenceMethod(MethodDesc method)76 public override bool WillUseMetadataTokenToReferenceMethod(MethodDesc method) 77 { 78 return false; 79 } 80 WillUseMetadataTokenToReferenceField(FieldDesc field)81 public override bool WillUseMetadataTokenToReferenceField(FieldDesc field) 82 { 83 return false; 84 } 85 86 private sealed class FullyBlockedMetadataPolicy : MetadataBlockingPolicy 87 { IsBlocked(MetadataType type)88 public override bool IsBlocked(MetadataType type) 89 { 90 Debug.Assert(type.IsTypeDefinition); 91 return true; 92 } 93 IsBlocked(MethodDesc method)94 public override bool IsBlocked(MethodDesc method) 95 { 96 Debug.Assert(method.IsTypicalMethodDefinition); 97 return true; 98 } 99 IsBlocked(FieldDesc field)100 public override bool IsBlocked(FieldDesc field) 101 { 102 Debug.Assert(field.IsTypicalFieldDefinition); 103 return true; 104 } 105 } 106 } 107 } 108