25using System.Collections.Generic;
26using System.Reflection.Metadata;
34 internal abstract class Module : ICustomAttributeProvider
37 readonly Universe universe;
82 internal Module(Universe universe)
84 this.universe = universe;
90 public Universe Universe => universe;
92 internal Table[] GetTables()
94 var tables =
new Table[64];
137 public virtual void __GetDataDirectoryEntry(
int index, out
int rva, out
int length)
139 throw new NotSupportedException();
142 public virtual long __RelativeVirtualAddressToFileOffset(
int rva)
144 throw new NotSupportedException();
147 public bool __GetSectionInfo(
int rva, out
string name, out
int characteristics)
149 return __GetSectionInfo(rva, out name, out characteristics, out _, out _, out _, out _);
152 public virtual bool __GetSectionInfo(
int rva, out
string name, out
int characteristics, out
int virtualAddress, out
int virtualSize, out
int pointerToRawData, out
int sizeOfRawData)
154 throw new NotSupportedException();
157 public virtual int __ReadDataFromRVA(
int rva,
byte[] data,
int offset,
int length)
159 throw new NotSupportedException();
162 public virtual void GetPEKind(out PortableExecutableKinds peKind, out ImageFileMachine machine)
164 throw new NotSupportedException();
167 public virtual int __Subsystem
169 get {
throw new NotSupportedException(); }
174 return GetField(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
177 public FieldInfo GetField(
string name, BindingFlags bindingFlags)
179 return IsResource() ? null : GetModuleType().GetField(name, bindingFlags | BindingFlags.DeclaredOnly);
184 return GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
187 public FieldInfo[] GetFields(BindingFlags bindingFlags)
189 return IsResource() ? Array.Empty<
FieldInfo>() : GetModuleType().GetFields(bindingFlags | BindingFlags.DeclaredOnly);
194 return IsResource() ? null : GetModuleType().GetMethod(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
199 return IsResource() ? null : GetModuleType().GetMethod(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly,
null, types,
null);
202 public MethodInfo GetMethod(
string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConv,
Type[] types, ParameterModifier[] modifiers)
204 return IsResource() ? null : GetModuleType().GetMethod(name, bindingAttr | BindingFlags.DeclaredOnly, binder, callConv, types, modifiers);
209 return GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
212 public MethodInfo[] GetMethods(BindingFlags bindingFlags)
214 return IsResource() ? Array.Empty<
MethodInfo>() : GetModuleType().GetMethods(bindingFlags | BindingFlags.DeclaredOnly);
219 get {
return IsResource() ? null : GetModuleType().TypeInitializer; }
222 public virtual byte[] ResolveSignature(
int metadataToken)
224 throw new NotSupportedException();
227 public virtual __StandAloneMethodSig __ResolveStandAloneMethodSig(
int metadataToken,
Type[] genericTypeArguments,
Type[] genericMethodArguments)
229 throw new NotSupportedException();
232 public virtual CustomModifiers __ResolveTypeSpecCustomModifiers(
int typeSpecToken,
Type[] genericTypeArguments,
Type[] genericMethodArguments)
234 throw new NotSupportedException();
237 public int MetadataToken
239 get {
return IsResource() ? 0 : 1; }
242 public abstract int MDStreamVersion {
get; }
246 public abstract string FullyQualifiedName {
get; }
248 public abstract string Name {
get; }
250 public abstract Guid ModuleVersionId {
get; }
252 public abstract MethodBase ResolveMethod(
int metadataToken,
Type[] genericTypeArguments,
Type[] genericMethodArguments);
254 public abstract FieldInfo ResolveField(
int metadataToken,
Type[] genericTypeArguments,
Type[] genericMethodArguments);
256 public abstract MemberInfo ResolveMember(
int metadataToken,
Type[] genericTypeArguments,
Type[] genericMethodArguments);
259 public abstract string ResolveString(
int metadataToken);
261 public abstract Type[] __ResolveOptionalParameterTypes(
int metadataToken,
Type[] genericTypeArguments,
Type[] genericMethodArguments, out CustomModifiers[] customModifiers);
263 public abstract string ScopeName {
get; }
265 internal abstract void GetTypesImpl(List<Type> list);
269 internal abstract Type FindTypeIgnoreCase(
TypeName lowerCaseName);
271 [Obsolete(
"Please use __ResolveOptionalParameterTypes(int, Type[], Type[], out CustomModifiers[]) instead.")]
272 public Type[] __ResolveOptionalParameterTypes(
int metadataToken)
274 CustomModifiers[] dummy;
275 return __ResolveOptionalParameterTypes(metadataToken,
null,
null, out dummy);
278 public Type GetType(
string className)
280 return GetType(className,
false,
false);
283 public Type GetType(
string className,
bool ignoreCase)
285 return GetType(className,
false, ignoreCase);
288 public Type GetType(
string className,
bool throwOnError,
bool ignoreCase)
294 if (parser.AssemblyName !=
null)
297 throw new ArgumentException(
"Type names passed to Module.GetType() must not specify an assembly.");
303 var type = ignoreCase ? FindTypeIgnoreCase(typeName.ToLowerInvariant()) : FindType(typeName);
304 if (type ==
null && __IsMissing)
307 return parser.Expand(type,
this, throwOnError, className,
false, ignoreCase);
310 public Type[] GetTypes()
312 var list =
new List<Type>();
314 return list.ToArray();
317 public Type[] FindTypes(TypeFilter filter,
object filterCriteria)
319 var list =
new List<Type>();
320 foreach (var type
in GetTypes())
321 if (filter(type, filterCriteria))
324 return list.ToArray();
327 public virtual bool IsResource()
332 public Type ResolveType(
int metadataToken)
334 return ResolveType(metadataToken,
null,
null);
340 readonly
Type[] genericTypeArguments;
341 readonly
Type[] genericMethodArguments;
348 internal GenericContext(
Type[] genericTypeArguments,
Type[] genericMethodArguments)
350 this.genericTypeArguments = genericTypeArguments;
351 this.genericMethodArguments = genericMethodArguments;
354 public Type GetGenericTypeArgument(
int index)
356 return genericTypeArguments[index];
359 public Type GetGenericMethodArgument(
int index)
361 return genericMethodArguments[index];
366 public Type ResolveType(
int metadataToken,
Type[] genericTypeArguments,
Type[] genericMethodArguments)
369 return ResolveType(metadataToken,
new GenericContext(genericTypeArguments, genericMethodArguments));
371 return ResolveType(metadataToken,
null);
376 public MethodBase ResolveMethod(
int metadataToken)
378 return ResolveMethod(metadataToken,
null,
null);
381 public FieldInfo ResolveField(
int metadataToken)
383 return ResolveField(metadataToken,
null,
null);
386 public MemberInfo ResolveMember(
int metadataToken)
388 return ResolveMember(metadataToken,
null,
null);
391 public bool IsDefined(
Type attributeType,
bool inherit)
393 return CustomAttributeData.__GetCustomAttributes(
this, attributeType, inherit).Count != 0;
396 public IList<CustomAttributeData> __GetCustomAttributes(
Type attributeType,
bool inherit)
398 return CustomAttributeData.__GetCustomAttributes(
this, attributeType, inherit);
401 public IList<CustomAttributeData> GetCustomAttributesData()
403 return CustomAttributeData.GetCustomAttributes(
this);
406 public IEnumerable<CustomAttributeData> CustomAttributes
408 get {
return GetCustomAttributesData(); }
411 public virtual IList<CustomAttributeData> __GetPlaceholderAssemblyCustomAttributes(
bool multiple,
bool security)
413 return Array.Empty<CustomAttributeData>();
416 public abstract AssemblyName[] __GetReferencedAssemblies();
418 public virtual void __ResolveReferencedAssemblies(
Assembly[] assemblies)
420 throw new NotSupportedException();
423 public abstract string[] __GetReferencedModules();
425 public abstract Type[] __GetReferencedTypes();
427 public abstract Type[] __GetExportedTypes();
429 public virtual bool __IsMissing =>
false;
431 public ulong __ImageBase => GetImageBaseImpl();
433 protected abstract ulong GetImageBaseImpl();
435 public ulong __StackReserve => GetStackReserveImpl();
437 protected abstract ulong GetStackReserveImpl();
439 public uint __FileAlignment => GetFileAlignmentImpl();
441 protected abstract uint GetFileAlignmentImpl();
443 public DllCharacteristics __DllCharacteristics => GetDllCharacteristicsImpl();
445 protected abstract DllCharacteristics GetDllCharacteristicsImpl();
447 public virtual byte[] __ModuleHash =>
throw new NotSupportedException();
449 public virtual int __EntryPointRVA =>
throw new NotSupportedException();
451 public virtual int __EntryPointToken =>
throw new NotSupportedException();
453 public virtual string __ImageRuntimeVersion =>
throw new NotSupportedException();
456 public List<CustomAttributeData> __GetCustomAttributesFor(
int token)
458 return CustomAttributeData.GetCustomAttributesImpl(
new List<CustomAttributeData>(),
this, token,
null);
461 public bool __TryGetImplMap(
int token, out ImplMapFlags mappingFlags, out
string importName, out
string importScope)
465 mappingFlags = (ImplMapFlags)(ushort)
ImplMapTable.records[i].MappingFlags;
466 importName = GetString(
ImplMapTable.records[i].ImportName);
477 public virtual System.Security.Cryptography.X509Certificates.X509Certificate GetSignerCertificate()
482 internal abstract Type GetModuleType();
484 internal IList<CustomAttributeData> GetDeclarativeSecurity(
int metadataToken)
486 var list =
new List<CustomAttributeData>();
488 CustomAttributeData.ReadDeclarativeSecurity(
this, i, list);
493 internal virtual void Dispose()
503 internal virtual string GetString(StringHandle handle)
505 throw new NotImplementedException();
508 internal virtual ByteReader GetBlobReader(BlobHandle handle)
510 throw new NotImplementedException();
515 internal delegate
bool TypeFilter(
Type m,
object filterCriteria);
517 internal delegate
bool MemberFilter(
MemberInfo m,
object filterCriteria);
IKVM.Reflection.Module Module
IKVM.Reflection.Type Type
IKVM.Reflection.Assembly Assembly
IKVM.Reflection.AssemblyName AssemblyName
IKVM.Reflection.ConstructorInfo ConstructorInfo
IKVM.Reflection.FieldInfo FieldInfo
IKVM.Reflection.MemberInfo MemberInfo
IKVM.Reflection.MethodInfo MethodInfo
IKVM.Reflection.MethodBase MethodBase
global::java.lang.invoke.LambdaForm.Name Name