cd81a8091ad0541e94a9762831a67b6908840676
[platform/upstream/dotnet/runtime.git] /
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.Collections.Generic;
6 using System.Diagnostics;
7
8 namespace System.Reflection.TypeLoading
9 {
10     /// <summary>
11     /// Resource-only modules created by a MetadataLoadContext.
12     /// </summary>
13     internal sealed class RoResourceModule : RoModule
14     {
15         private readonly RoAssembly _assembly;
16
17         //
18         // "fullyQualifiedName" determines the string returned by Module.FullyQualifiedName. It is typically set to the full path of the
19         // file on disk containing the module.
20         //
21         internal RoResourceModule(RoAssembly assembly, string fullyQualifiedName)
22             : base(fullyQualifiedName)
23         {
24             Debug.Assert(assembly != null);
25             Debug.Assert(fullyQualifiedName != null);
26             _assembly = assembly;
27         }
28
29         internal sealed override RoAssembly GetRoAssembly() => _assembly;
30
31         public sealed override int MDStreamVersion => throw new InvalidOperationException(SR.ResourceOnlyModule);
32         public sealed override int MetadataToken => 0x00000000;
33         public sealed override Guid ModuleVersionId => throw new InvalidOperationException(SR.ResourceOnlyModule);
34         public sealed override string ScopeName => Name;
35         public sealed override void GetPEKind(out PortableExecutableKinds peKind, out ImageFileMachine machine)
36         {
37             peKind = PortableExecutableKinds.NotAPortableExecutableImage;
38             machine = default;
39         }
40
41         public sealed override IEnumerable<CustomAttributeData> CustomAttributes => Array.Empty<CustomAttributeData>();
42
43         public sealed override FieldInfo GetField(string name, BindingFlags bindingAttr) => null;
44         public sealed override FieldInfo[] GetFields(BindingFlags bindingFlags) => Array.Empty<FieldInfo>();
45         public sealed override MethodInfo[] GetMethods(BindingFlags bindingFlags) => Array.Empty<MethodInfo>();
46         protected sealed override MethodInfo GetMethodImpl(string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) => null;
47
48         public sealed override bool IsResource() => true;
49
50         public sealed override Type[] GetTypes() => Array.Empty<Type>();
51         protected sealed override RoDefinitionType GetTypeCoreNoCache(ReadOnlySpan<byte> ns, ReadOnlySpan<byte> name, out Exception e)
52         {
53             e = new TypeLoadException(SR.Format(SR.TypeNotFound, ns.ToUtf16().AppendTypeName(name.ToUtf16()), Assembly));
54             return null;
55         }
56
57         internal sealed override IEnumerable<RoType> GetDefinedRoTypes() => null;
58     }
59 }