17 private RuntimeModule m_ptr;
23 [SecuritySafeCritical]
26 return GetMDStreamVersion(GetRuntimeModule().GetNativeHandle());
35 internal ModuleHandle(RuntimeModule module)
40 internal RuntimeModule GetRuntimeModule()
45 internal bool IsNullHandle()
58 return m_ptr.GetHashCode();
65 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.Success)]
66 public override bool Equals(
object obj)
73 return moduleHandle.m_ptr == m_ptr;
80 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.Success)]
83 return handle.m_ptr == m_ptr;
103 return !left.
Equals(right);
108 internal static extern IRuntimeMethodInfo GetDynamicMethod(
DynamicMethod method, RuntimeModule module,
string name,
byte[] sig, Resolver resolver);
112 internal static extern int GetToken(RuntimeModule module);
114 private static void ValidateModulePointer(RuntimeModule module)
140 return new RuntimeTypeHandle(ResolveTypeHandleInternal(GetRuntimeModule(), typeToken,
null,
null));
157 return new RuntimeTypeHandle(ResolveTypeHandleInternal(GetRuntimeModule(), typeToken, typeInstantiationContext, methodInstantiationContext));
160 [SecuritySafeCritical]
161 internal unsafe
static RuntimeType ResolveTypeHandleInternal(RuntimeModule module,
int typeToken,
RuntimeTypeHandle[] typeInstantiationContext,
RuntimeTypeHandle[] methodInstantiationContext)
163 ValidateModulePointer(module);
164 if (!GetMetadataImport(module).IsValidToken(typeToken))
169 IntPtr[] array = RuntimeTypeHandle.CopyRuntimeTypeHandles(typeInstantiationContext, out length);
171 IntPtr[] array2 = RuntimeTypeHandle.CopyRuntimeTypeHandles(methodInstantiationContext, out length2);
172 IntPtr[] array3 = array;
173 fixed (IntPtr* typeInstArgs = array3)
175 IntPtr[] array4 = array2;
176 fixed (IntPtr* methodInstArgs = array4)
178 RuntimeType o =
null;
179 ResolveType(module, typeToken, typeInstArgs, length, methodInstArgs, length2, JitHelpers.GetObjectHandleOnStack(ref o));
180 GC.KeepAlive(typeInstantiationContext);
181 GC.KeepAlive(methodInstantiationContext);
189 [SuppressUnmanagedCodeSecurity]
190 private unsafe
static extern void ResolveType(RuntimeModule module,
int typeToken, IntPtr* typeInstArgs,
int typeInstCount, IntPtr* methodInstArgs,
int methodInstCount, ObjectHandleOnStack type);
213 internal static IRuntimeMethodInfo ResolveMethodHandleInternal(RuntimeModule module,
int methodToken)
215 return ResolveMethodHandleInternal(module, methodToken,
null,
null);
232 return new RuntimeMethodHandle(ResolveMethodHandleInternal(GetRuntimeModule(), methodToken, typeInstantiationContext, methodInstantiationContext));
235 [SecuritySafeCritical]
236 internal static IRuntimeMethodInfo ResolveMethodHandleInternal(RuntimeModule module,
int methodToken,
RuntimeTypeHandle[] typeInstantiationContext,
RuntimeTypeHandle[] methodInstantiationContext)
239 IntPtr[] typeInstantiationContext2 =
RuntimeTypeHandle.CopyRuntimeTypeHandles(typeInstantiationContext, out length);
241 IntPtr[] methodInstantiationContext2 =
RuntimeTypeHandle.CopyRuntimeTypeHandles(methodInstantiationContext, out length2);
242 RuntimeMethodHandleInternal runtimeMethodHandleInternal = ResolveMethodHandleInternalCore(module, methodToken, typeInstantiationContext2, length, methodInstantiationContext2, length2);
243 IRuntimeMethodInfo result =
new RuntimeMethodInfoStub(runtimeMethodHandleInternal,
RuntimeMethodHandle.GetLoaderAllocator(runtimeMethodHandleInternal));
250 internal unsafe
static RuntimeMethodHandleInternal ResolveMethodHandleInternalCore(RuntimeModule module,
int methodToken, IntPtr[] typeInstantiationContext,
int typeInstCount, IntPtr[] methodInstantiationContext,
int methodInstCount)
252 ValidateModulePointer(module);
253 if (!GetMetadataImport(module.GetNativeHandle()).IsValidToken(methodToken))
255 throw new ArgumentOutOfRangeException(
"metadataToken", Environment.GetResourceString(
"Argument_InvalidToken", methodToken,
new ModuleHandle(module)));
257 fixed (IntPtr* typeInstArgs = typeInstantiationContext)
259 fixed (IntPtr* methodInstArgs = methodInstantiationContext)
261 return ResolveMethod(module.GetNativeHandle(), methodToken, typeInstArgs, typeInstCount, methodInstArgs, methodInstCount);
268 [SuppressUnmanagedCodeSecurity]
269 private unsafe
static extern RuntimeMethodHandleInternal ResolveMethod(RuntimeModule module,
int methodToken, IntPtr* typeInstArgs,
int typeInstCount, IntPtr* methodInstArgs,
int methodInstCount);
289 return new RuntimeFieldHandle(ResolveFieldHandleInternal(GetRuntimeModule(), fieldToken,
null,
null));
306 return new RuntimeFieldHandle(ResolveFieldHandleInternal(GetRuntimeModule(), fieldToken, typeInstantiationContext, methodInstantiationContext));
309 [SecuritySafeCritical]
310 internal unsafe
static IRuntimeFieldInfo ResolveFieldHandleInternal(RuntimeModule module,
int fieldToken,
RuntimeTypeHandle[] typeInstantiationContext,
RuntimeTypeHandle[] methodInstantiationContext)
312 ValidateModulePointer(module);
313 if (!GetMetadataImport(module.GetNativeHandle()).IsValidToken(fieldToken))
318 IntPtr[] array = RuntimeTypeHandle.CopyRuntimeTypeHandles(typeInstantiationContext, out length);
320 IntPtr[] array2 = RuntimeTypeHandle.CopyRuntimeTypeHandles(methodInstantiationContext, out length2);
321 IntPtr[] array3 = array;
322 fixed (IntPtr* typeInstArgs = array3)
324 IntPtr[] array4 = array2;
325 fixed (IntPtr* methodInstArgs = array4)
327 IRuntimeFieldInfo o =
null;
328 ResolveField(module.GetNativeHandle(), fieldToken, typeInstArgs, length, methodInstArgs, length2, JitHelpers.GetObjectHandleOnStack(ref o));
329 GC.KeepAlive(typeInstantiationContext);
330 GC.KeepAlive(methodInstantiationContext);
338 [SuppressUnmanagedCodeSecurity]
339 private unsafe
static extern void ResolveField(RuntimeModule module,
int fieldToken, IntPtr* typeInstArgs,
int typeInstCount, IntPtr* methodInstArgs,
int methodInstCount, ObjectHandleOnStack retField);
343 [SuppressUnmanagedCodeSecurity]
344 private static extern bool _ContainsPropertyMatchingHash(RuntimeModule module,
int propertyToken, uint hash);
347 internal static bool ContainsPropertyMatchingHash(RuntimeModule module,
int propertyToken, uint hash)
349 return _ContainsPropertyMatchingHash(module.GetNativeHandle(), propertyToken, hash);
354 [SuppressUnmanagedCodeSecurity]
355 private static extern void GetAssembly(RuntimeModule handle, ObjectHandleOnStack retAssembly);
357 [SecuritySafeCritical]
358 internal static RuntimeAssembly GetAssembly(RuntimeModule module)
360 RuntimeAssembly o =
null;
361 GetAssembly(module.GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref o));
367 [SuppressUnmanagedCodeSecurity]
368 internal static extern void GetModuleType(RuntimeModule handle, ObjectHandleOnStack type);
370 [SecuritySafeCritical]
371 internal static RuntimeType GetModuleType(RuntimeModule module)
373 RuntimeType o =
null;
374 GetModuleType(module.GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref o));
380 [SuppressUnmanagedCodeSecurity]
381 private static extern void GetPEKind(RuntimeModule handle, out
int peKind, out
int machine);
383 [SecuritySafeCritical]
386 GetPEKind(module.GetNativeHandle(), out
int peKind2, out
int machine2);
393 internal static extern int GetMDStreamVersion(RuntimeModule module);
397 private static extern IntPtr _GetMetadataImport(RuntimeModule module);
400 internal static MetadataImport GetMetadataImport(RuntimeModule module)
402 return new MetadataImport(_GetMetadataImport(module.GetNativeHandle()), module);
override bool Equals(object obj)
Returns a T:System.Boolean value indicating whether the specified object is a T:System....
RuntimeTypeHandle ResolveTypeHandle(int typeToken)
Returns a runtime type handle for the type identified by the specified metadata token.
RuntimeTypeHandle ResolveTypeHandle(int typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
Returns a runtime type handle for the type identified by the specified metadata token,...
Defines and represents a dynamic method that can be compiled, executed, and discarded....
int MDStreamVersion
Gets the metadata stream version.
static bool operator==(ModuleHandle left, ModuleHandle right)
Tests whether two T:System.ModuleHandle structures are equal.
RuntimeMethodHandle ResolveMethodHandle(int methodToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
Returns a runtime method handle for the method or constructor identified by the specified metadata to...
Represents a field using an internal metadata token.
The exception that is thrown when the value of an argument is outside the allowable range of values a...
ImageFileMachine
Identifies the platform targeted by an executable.
Represents a runtime handle for a module.
static void KeepAlive(object obj)
References the specified object, which makes it ineligible for garbage collection from the start of t...
Represents a type using an internal metadata token.
RuntimeMethodHandle ResolveMethodHandle(int methodToken)
Returns a runtime method handle for the method or constructor identified by the specified metadata to...
override int GetHashCode()
Returns the hash code for this instance.
Cer
Specifies a method's behavior when called within a constrained execution region.
Provides information about, and means to manipulate, the current environment and platform....
T:System.RuntimeMethodHandle is a handle to the internal metadata representation of a method.
A platform-specific type that is used to represent a pointer or a handle.
RuntimeFieldHandle GetRuntimeFieldHandleFromMetadataToken(int fieldToken)
Returns a runtime handle for the field identified by the specified metadata token.
bool Equals(ModuleHandle handle)
Returns a T:System.Boolean value indicating whether the specified T:System.ModuleHandle structure is ...
MethodImplOptions
Defines the details of how a method is implemented.
CharSet
Dictates which character set marshaled strings should use.
Controls the system garbage collector, a service that automatically reclaims unused memory.
RuntimeFieldHandle ResolveFieldHandle(int fieldToken)
Returns a runtime handle for the field identified by the specified metadata token.
RuntimeMethodHandle GetRuntimeMethodHandleFromMetadataToken(int methodToken)
Returns a runtime method handle for the method or constructor identified by the specified metadata to...
static bool operator !=(ModuleHandle left, ModuleHandle right)
Tests whether two T:System.ModuleHandle structures are unequal.
PortableExecutableKinds
Identifies the nature of the code in an executable file.
static readonly ModuleHandle EmptyHandle
Represents an empty module handle.
The exception that is thrown when a method call is invalid for the object's current state.
Consistency
Specifies a reliability contract.
RuntimeTypeHandle GetRuntimeTypeHandleFromMetadataToken(int typeToken)
Returns a runtime type handle for the type identified by the specified metadata token.
RuntimeFieldHandle ResolveFieldHandle(int fieldToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
Returns a runtime field handle for the field identified by the specified metadata token,...