public OpenMethodResolver(RuntimeTypeHandle declaringTypeOfSlot, int slot, int handle) { _resolveType = DispatchResolve; _declaringType = declaringTypeOfSlot.ToEETypePtr(); _methodHandleOrSlotOrCodePointer = new IntPtr(slot); _handle = handle; }
public unsafe OpenMethodResolver(RuntimeTypeHandle declaringTypeOfSlot, RuntimeMethodHandle gvmSlot, int handle) { _resolveType = GVMResolve; _methodHandleOrSlotOrCodePointer = *(IntPtr*)&gvmSlot; _declaringType = declaringTypeOfSlot.ToEETypePtr(); _handle = handle; }
public OpenMethodResolver(RuntimeTypeHandle declaringType, IntPtr codePointer, int handle) { _resolveType = OpenNonVirtualResolve; _methodHandleOrSlotOrCodePointer = codePointer; _declaringType = declaringType.ToEETypePtr(); _handle = handle; }
public NoMetadataType(TypeSystemContext context, RuntimeTypeHandle genericTypeDefinition, DefType genericTypeDefinitionAsDefType, Instantiation instantiation, int hashcode) { _hashcode = hashcode; _context = context; _genericTypeDefinition = genericTypeDefinition; _genericTypeDefinitionAsDefType = genericTypeDefinitionAsDefType; if (_genericTypeDefinitionAsDefType == null) _genericTypeDefinitionAsDefType = this; _instantiation = instantiation; // Instantiation must either be: // Something valid (if the type is generic, or a generic type definition) // or Empty (if the type isn't a generic of any form) unsafe { Debug.Assert(((_instantiation.Length > 0) && _genericTypeDefinition.ToEETypePtr()->IsGenericTypeDefinition) || ((_instantiation.Length == 0) && !_genericTypeDefinition.ToEETypePtr()->IsGenericTypeDefinition)); } }
// Various functions in static access need to create permanent pointers for use by thread static lookup. #region GC/Non-GC Statics /// <summary> /// Get a pointer to the nongc static field data of a type. This function works for dynamic /// types, reflectable types, and for all generic types /// </summary> public IntPtr TryGetNonGcStaticFieldDataDirect(RuntimeTypeHandle runtimeTypeHandle) { unsafe { EEType* typeAsEEType = runtimeTypeHandle.ToEETypePtr(); // Non-generic, non-dynamic types need special handling. if (!typeAsEEType->IsDynamicType && !typeAsEEType->IsGeneric) { if (typeAsEEType->HasCctor) { // The non-gc area for a type is immediately following its cctor context if it has one IntPtr dataAddress = TryGetStaticClassConstructionContext(runtimeTypeHandle); if (dataAddress != IntPtr.Zero) { return (IntPtr)(((byte*)dataAddress.ToPointer()) + sizeof(System.Runtime.CompilerServices.StaticClassConstructionContext)); } } else { // If the type does not have a Cctor context, search for the field on the type in the field map which has the lowest offset, // yet has the the correct type of storage. IntPtr staticAddress; if (TryGetStaticFieldBaseFromFieldAccessMap(runtimeTypeHandle, FieldAccessStaticDataKind.NonGC, out staticAddress)) { return staticAddress; } } } } IntPtr nonGcStaticsAddress; IntPtr gcStaticsAddress; if (TryGetStaticsInfoForNamedType(runtimeTypeHandle, out nonGcStaticsAddress, out gcStaticsAddress)) { return nonGcStaticsAddress; } // The indirected helper function can be used to find all dynamic types not found via // TryGetStaticsInfoForNamedType as well as generics IntPtr ptrToStaticFieldData = TryGetNonGcStaticFieldData(runtimeTypeHandle); if (ptrToStaticFieldData == IntPtr.Zero) { return IntPtr.Zero; } else { unsafe { return *(IntPtr*)ptrToStaticFieldData; } } }
public bool Equals(RuntimeTypeHandle handle) { if (_value == handle._value) { return true; } else if (this.IsNull || handle.IsNull) { return false; } else { return RuntimeImports.AreTypesEquivalent(this.ToEETypePtr(), handle.ToEETypePtr()); } }
private static unsafe IntPtr GVMLookupForSlotWorker(RuntimeTypeHandle type, RuntimeTypeHandle declaringType, RuntimeTypeHandle[] genericArguments, MethodNameAndSignature methodNameAndSignature) { bool slotChanged = false; IntPtr resolution = IntPtr.Zero; // Otherwise, walk parent hierarchy attempting to resolve EETypePtr eetype = type.ToEETypePtr(); IntPtr functionPointer = IntPtr.Zero; IntPtr genericDictionary = IntPtr.Zero; while (!eetype.IsNull) { RuntimeTypeHandle handle = new RuntimeTypeHandle(eetype); string methodName = methodNameAndSignature.Name; RuntimeMethodSignature methodSignature = methodNameAndSignature.Signature; if (RuntimeAugments.TypeLoaderCallbacks.TryGetGenericVirtualTargetForTypeAndSlot(handle, ref declaringType, genericArguments, ref methodName, ref methodSignature, out functionPointer, out genericDictionary, out slotChanged)) { methodNameAndSignature = new MethodNameAndSignature(methodName, methodSignature); if (!slotChanged) resolution = FunctionPointerOps.GetGenericMethodFunctionPointer(functionPointer, genericDictionary); break; } eetype = eetype.BaseType; } // If the current slot to examine has changed, restart the lookup. // This happens when there is an interface call. if (slotChanged) { return GVMLookupForSlotWorker(type, declaringType, genericArguments, methodNameAndSignature); } if (resolution == IntPtr.Zero) { Environment.FailFast("GVM resolution failure"); } return resolution; }
public bool Equals(RuntimeTypeHandle handle) { #if CORERT return Object.ReferenceEquals(_type, handle._type); #else if (_value == handle._value) { return true; } else if (this.IsNull || handle.IsNull) { return false; } else { return RuntimeImports.AreTypesEquivalent(this.ToEETypePtr(), handle.ToEETypePtr()); } #endif }
public static object DynamicInvokeParamHelperCore(RuntimeTypeHandle type, out DynamicInvokeParamLookupType paramLookupType, out int index, DynamicInvokeParamType paramType) { index = s_curIndex++; int parametersLength = s_parameters != null ? s_parameters.Length : 0; if (index >= parametersLength) { throw new System.Reflection.TargetParameterCountException(); } object incomingParam = s_parameters[index]; // Handle default parameters if ((incomingParam == System.Reflection.Missing.Value) && paramType == DynamicInvokeParamType.In) { incomingParam = GetDefaultValue(type, index); // The default value is captured into the parameters array s_parameters[index] = incomingParam; } RuntimeTypeHandle widenAndCompareType = type; bool nullable = RuntimeImports.RhIsNullable(type.ToEETypePtr()); if (nullable) { widenAndCompareType = new RuntimeTypeHandle(RuntimeImports.RhGetNullableType(type.ToEETypePtr())); } if (widenAndCompareType.ToEETypePtr().IsPrimitive || type.ToEETypePtr().IsEnum) { // Nullable requires exact matching if (incomingParam != null) { if ((nullable || paramType == DynamicInvokeParamType.Ref) && incomingParam != null) { if (widenAndCompareType.ToEETypePtr() != incomingParam.EETypePtr) { throw CreateChangeTypeArgumentException(incomingParam.EETypePtr, type.ToEETypePtr()); } } else { if (widenAndCompareType.ToEETypePtr().CorElementType != incomingParam.EETypePtr.CorElementType) { System.Diagnostics.Debug.Assert(paramType == DynamicInvokeParamType.In); incomingParam = InvokeUtils.CheckArgument(incomingParam, widenAndCompareType.ToEETypePtr(), InvokeUtils.CheckArgumentSemantics.DynamicInvoke); } } } return(DynamicInvokeBoxedValuetypeReturn(out paramLookupType, incomingParam, index, type, paramType)); } else if (type.ToEETypePtr().IsValueType) { incomingParam = InvokeUtils.CheckArgument(incomingParam, type.ToEETypePtr(), InvokeUtils.CheckArgumentSemantics.DynamicInvoke); System.Diagnostics.Debug.Assert(s_parameters[index] == null || Object.ReferenceEquals(incomingParam, s_parameters[index])); return(DynamicInvokeBoxedValuetypeReturn(out paramLookupType, incomingParam, index, type, paramType)); } else { incomingParam = InvokeUtils.CheckArgument(incomingParam, widenAndCompareType.ToEETypePtr(), InvokeUtils.CheckArgumentSemantics.DynamicInvoke); System.Diagnostics.Debug.Assert(Object.ReferenceEquals(incomingParam, s_parameters[index])); paramLookupType = DynamicInvokeParamLookupType.IndexIntoObjectArrayReturned; return(s_parameters); } }
// // Various reflection scenarios (Array.SetValue(), reflection Invoke, delegate DynamicInvoke and FieldInfo.Set()) perform // automatic conveniences such as automatically widening primitive types to fit the destination type. // // This method attempts to collect as much of that logic as possible in place. (This may not be completely possible // as the desktop CLR is not particularly consistent across all these scenarios either.) // // The transforms supported are: // // Value-preserving widenings of primitive integrals and floats. // Enums can be converted to the same or wider underlying primitive. // Primitives can be converted to an enum with the same or wider underlying primitive. // // null converted to default(T) (this is important when T is a valuetype.) // // There is also another transform of T -> Nullable<T>. This method acknowledges that rule but does not actually transform the T. // Rather, the transformation happens naturally when the caller unboxes the value to its final destination. // // This method is targeted by the Delegate ILTransformer. // // public static object?CheckArgument(object?srcObject, RuntimeTypeHandle dstType, BinderBundle?binderBundle) { EETypePtr dstEEType = dstType.ToEETypePtr(); return(CheckArgument(srcObject, dstEEType, CheckArgumentSemantics.DynamicInvoke, binderBundle, ref Unsafe.NullRef <ArgSetupState>())); }
// // Various reflection scenarios (Array.SetValue(), reflection Invoke, delegate DynamicInvoke and FieldInfo.Set()) perform // automatic conveniences such as automatically widening primitive types to fit the destination type. // // This method attempts to collect as much of that logic as possible in place. (This may not be completely possible // as the desktop CLR is not particularly consistent across all these scenarios either.) // // The transforms supported are: // // Value-preserving widenings of primitive integrals and floats. // Enums can be converted to the same or wider underlying primitive. // Primitives can be converted to an enum with the same or wider underlying primitive. // // null converted to default(T) (this is important when T is a valuetype.) // // There is also another transform of T -> Nullable<T>. This method acknowleges that rule but does not actually transform the T. // Rather, the transformation happens naturally when the caller unboxes the value to its final destination. // // This method is targeted by the Delegate ILTransformer. // // public static Object CheckArgument(Object srcObject, RuntimeTypeHandle dstType) { EETypePtr dstEEType = dstType.ToEETypePtr(); return(CheckArgument(srcObject, dstEEType, CheckArgumentSemantics.DynamicInvoke)); }
internal static object DynamicInvokeParamHelperCore(RuntimeTypeHandle type, out DynamicInvokeParamLookupType paramLookupType, out int index, DynamicInvokeParamType paramType) { index = s_curIndex++; int parametersLength = s_parameters != null ? s_parameters.Length : 0; if (index >= parametersLength) throw new System.Reflection.TargetParameterCountException(); object incomingParam = s_parameters[index]; // Handle default parameters if ((incomingParam == System.Reflection.Missing.Value) && paramType == DynamicInvokeParamType.In) { incomingParam = GetDefaultValue(type, index); // The default value is captured into the parameters array s_parameters[index] = incomingParam; } RuntimeTypeHandle widenAndCompareType = type; bool nullable = RuntimeImports.RhIsNullable(type.ToEETypePtr()); if (nullable) { widenAndCompareType = new RuntimeTypeHandle(RuntimeImports.RhGetNullableType(type.ToEETypePtr())); } if (widenAndCompareType.ToEETypePtr().IsPrimitive || type.ToEETypePtr().IsEnum) { // Nullable requires exact matching if (incomingParam != null) { if ((nullable || paramType == DynamicInvokeParamType.Ref) && incomingParam != null) { if (widenAndCompareType.ToEETypePtr() != incomingParam.EETypePtr) { throw CreateChangeTypeArgumentException(incomingParam.EETypePtr, type.ToEETypePtr()); } } else { if (widenAndCompareType.ToEETypePtr().CorElementType != incomingParam.EETypePtr.CorElementType) { System.Diagnostics.Debug.Assert(paramType == DynamicInvokeParamType.In); incomingParam = InvokeUtils.CheckArgument(incomingParam, widenAndCompareType.ToEETypePtr(), InvokeUtils.CheckArgumentSemantics.DynamicInvoke); } } } return DynamicInvokeBoxedValuetypeReturn(out paramLookupType, incomingParam, index, type, paramType); } else if (type.ToEETypePtr().IsValueType) { incomingParam = InvokeUtils.CheckArgument(incomingParam, type.ToEETypePtr(), InvokeUtils.CheckArgumentSemantics.DynamicInvoke); System.Diagnostics.Debug.Assert(s_parameters[index] == null || Object.ReferenceEquals(incomingParam, s_parameters[index])); return DynamicInvokeBoxedValuetypeReturn(out paramLookupType, incomingParam, index, type, paramType); } else { incomingParam = InvokeUtils.CheckArgument(incomingParam, widenAndCompareType.ToEETypePtr(), InvokeUtils.CheckArgumentSemantics.DynamicInvoke); System.Diagnostics.Debug.Assert(Object.ReferenceEquals(incomingParam, s_parameters[index])); paramLookupType = DynamicInvokeParamLookupType.IndexIntoObjectArrayReturned; return s_parameters; } }
public static unsafe void SetGenericDefinition(this RuntimeTypeHandle rtth, RuntimeTypeHandle genericDefinitionHandle) { rtth.ToEETypePtr()->GenericDefinition = genericDefinitionHandle.ToEETypePtr(); }
/// <summary> /// Get a pointer to the gc static field data of a type. This function works for dynamic /// types, reflectable types, and for all generic types /// </summary> public IntPtr TryGetGcStaticFieldDataDirect(RuntimeTypeHandle runtimeTypeHandle) { unsafe { // Non-generic, non-dynamic static data is found via the FieldAccessMap EEType* typeAsEEType = runtimeTypeHandle.ToEETypePtr(); // Non-generic, non-dynamic types need special handling. if (!typeAsEEType->IsDynamicType && !typeAsEEType->IsGeneric) { //search for the field on the type in the field map which has the lowest offset, // yet has the the correct type of storage. IntPtr staticAddress; if (TryGetStaticFieldBaseFromFieldAccessMap(runtimeTypeHandle, FieldAccessStaticDataKind.GC, out staticAddress)) { return staticAddress; } else { return IntPtr.Zero; } } } IntPtr nonGcStaticsAddress; IntPtr gcStaticsAddress; if (TryGetStaticsInfoForNamedType(runtimeTypeHandle, out nonGcStaticsAddress, out gcStaticsAddress)) { return gcStaticsAddress; } // The indirected helper function can be used to find all dynamic types not found via // TryGetStaticsInfoForNamedType as well as generics IntPtr ptrToStaticFieldData = TryGetGcStaticFieldData(runtimeTypeHandle); if (ptrToStaticFieldData == IntPtr.Zero) { return IntPtr.Zero; } else { unsafe { return *(IntPtr*)ptrToStaticFieldData; } } }
public static unsafe void SetBaseType(this RuntimeTypeHandle rtth, RuntimeTypeHandle baseTypeHandle) { rtth.ToEETypePtr()->BaseType = baseTypeHandle.ToEETypePtr(); }
private static unsafe object GetDefaultValue(RuntimeTypeHandle thType, int argIndex) { // Group index of 0 indicates there are no default parameters if (s_defaultValueString == null) { throw new ArgumentException(SR.Arg_DefaultValueMissingException); } StringDataParser dataParser = new StringDataParser(s_defaultValueString); // Skip to current argument int curArgIndex = 0; while (curArgIndex != argIndex) { int skip = dataParser.GetInt(); dataParser.Skip(skip); curArgIndex++; } // Discard size of current argument int sizeOfCurrentArg = dataParser.GetInt(); int defaultValueType = dataParser.GetInt(); switch (defaultValueType) { case DefaultParamTypeNone: default: throw new ArgumentException(SR.Arg_DefaultValueMissingException); case DefaultParamTypeString: return(dataParser.GetString()); case DefaultParamTypeDefault: if (thType.ToEETypePtr().IsValueType) { if (RuntimeImports.RhIsNullable(thType.ToEETypePtr())) { return(null); } else { return(RuntimeImports.RhNewObject(thType.ToEETypePtr())); } } else { return(null); } case DefaultParamTypeBool: return(dataParser.GetInt() == 1); case DefaultParamTypeChar: return((char)dataParser.GetInt()); case DefaultParamTypeI1: return((sbyte)dataParser.GetInt()); case DefaultParamTypeI2: return((short)dataParser.GetInt()); case DefaultParamTypeI4: return(dataParser.GetInt()); case DefaultParamTypeI8: return(dataParser.GetLong()); case DefaultParamTypeR4: return(dataParser.GetFloat()); case DefaultParamTypeR8: return(dataParser.GetDouble()); case DefaultParamTypeDecimal: int[] decimalBits = new int[4]; decimalBits[0] = dataParser.GetInt(); decimalBits[1] = dataParser.GetInt(); decimalBits[2] = dataParser.GetInt(); decimalBits[3] = dataParser.GetInt(); return(new Decimal(decimalBits)); case DefaultParamTypeDateTime: return(new DateTime(dataParser.GetLong())); case DefaultParamTypeNoneButOptional: return(System.Reflection.Missing.Value); } }
// // Various reflection scenarios (Array.SetValue(), reflection Invoke, delegate DynamicInvoke and FieldInfo.Set()) perform // automatic conveniences such as automatically widening primitive types to fit the destination type. // // This method attempts to collect as much of that logic as possible in place. (This may not be completely possible // as the desktop CLR is not particularly consistent across all these scenarios either.) // // The transforms supported are: // // Value-preserving widenings of primitive integrals and floats. // Enums can be converted to the same or wider underlying primitive. // Primitives can be converted to an enum with the same or wider underlying primitive. // // null converted to default(T) (this is important when T is a valuetype.) // // There is also another transform of T -> Nullable<T>. This method acknowleges that rule but does not actually transform the T. // Rather, the transformation happens naturally when the caller unboxes the value to its final destination. // // This method is targeted by the Delegate ILTransformer. // // public static Object CheckArgument(Object srcObject, RuntimeTypeHandle dstType, BinderBundle binderBundle) { EETypePtr dstEEType = dstType.ToEETypePtr(); return(CheckArgument(srcObject, dstEEType, CheckArgumentSemantics.DynamicInvoke, binderBundle, getExactTypeForCustomBinder: null)); }
public static unsafe void SetNullableType(this RuntimeTypeHandle rtth, RuntimeTypeHandle T_typeHandle) { rtth.ToEETypePtr()->NullableType = T_typeHandle.ToEETypePtr(); }
/// <summary> /// Retrieves the default value for a parameter of the delegate. /// </summary> /// <param name="thType">The type of the parameter to retrieve.</param> /// <param name="argIndex">The index of the parameter on the method to retrieve.</param> /// <param name="defaultValue">The default value of the parameter if available.</param> /// <returns>true if the default parameter value is available, otherwise false.</returns> internal bool TryGetDefaultParameterValue(RuntimeTypeHandle thType, int argIndex, out object defaultValue) { defaultValue = null; // The LoadDefaultValueString() has the following contract // If it returns false, the delegate invoke does not have default values. // If it returns true, then the s_DefaultValueString variable is set to // describe the default values for this invoke. string defaultValueString = null; if (LoadDefaultValueString()) { defaultValueString = s_DefaultValueString; } // Group index of 0 indicates there are no default parameters if (defaultValueString == null) { return false; } StringDataParser dataParser = new StringDataParser(defaultValueString); // Skip to current argument int curArgIndex = 0; while (curArgIndex != argIndex) { int skip = dataParser.GetInt(); dataParser.Skip(skip); curArgIndex++; } // Discard size of current argument int sizeOfCurrentArg = dataParser.GetInt(); int defaultValueType = dataParser.GetInt(); switch (defaultValueType) { case DefaultParamTypeNone: default: return false; case DefaultParamTypeString: defaultValue = dataParser.GetString(); return true; case DefaultParamTypeDefault: if (thType.ToEETypePtr().IsValueType) { if (thType.ToEETypePtr().IsNullable) { defaultValue = null; return true; } else { defaultValue = RuntimeImports.RhNewObject(thType.ToEETypePtr()); return true; } } else { defaultValue = null; return true; } case DefaultParamTypeBool: defaultValue = (dataParser.GetInt() == 1); return true; case DefaultParamTypeChar: defaultValue = (char)dataParser.GetInt(); return true; case DefaultParamTypeI1: defaultValue = (sbyte)dataParser.GetInt(); return true; case DefaultParamTypeUI1: defaultValue = (byte)dataParser.GetInt(); return true; case DefaultParamTypeI2: defaultValue = (short)dataParser.GetInt(); return true; case DefaultParamTypeUI2: defaultValue = (ushort)dataParser.GetInt(); return true; case DefaultParamTypeI4: defaultValue = dataParser.GetInt(); return true; case DefaultParamTypeUI4: defaultValue = checked((uint)dataParser.GetLong()); return true; case DefaultParamTypeI8: defaultValue = dataParser.GetLong(); return true; case DefaultParamTypeUI8: defaultValue = (ulong)dataParser.GetLong(); return true; case DefaultParamTypeR4: defaultValue = dataParser.GetFloat(); return true; case DefaultParamTypeR8: defaultValue = dataParser.GetDouble(); return true; case DefaultParamTypeDecimal: int[] decimalBits = new int[4]; decimalBits[0] = dataParser.GetInt(); decimalBits[1] = dataParser.GetInt(); decimalBits[2] = dataParser.GetInt(); decimalBits[3] = dataParser.GetInt(); defaultValue = new Decimal(decimalBits); return true; case DefaultParamTypeDateTime: defaultValue = new DateTime(dataParser.GetLong()); return true; case DefaultParamTypeNoneButOptional: defaultValue = System.Reflection.Missing.Value; return true; } }
/// <summary> /// Get a pointer to a pointer to the nongc static field data of a type. This function works for all generic types /// </summary> public IntPtr TryGetNonGcStaticFieldData(RuntimeTypeHandle runtimeTypeHandle) { unsafe { // Non-generic, non-dynamic static data is found via the FieldAccessMap EEType* typeAsEEType = runtimeTypeHandle.ToEETypePtr(); // Non-generic, non-dynamic types need special handling. Debug.Assert(typeAsEEType->IsDynamicType || typeAsEEType->IsGeneric); } // Search hashtable for static entry ExternalReferencesTable staticInfoLookup; var parser = GetStaticInfo(runtimeTypeHandle, out staticInfoLookup); if (!parser.IsNull) { var index = parser.GetUnsignedForBagElementKind(BagElementKind.NonGcStaticData); return index.HasValue ? staticInfoLookup.GetIntPtrFromIndex(index.Value) : IntPtr.Zero; } // Not found in hashtable... must be a dynamically created type Debug.Assert(runtimeTypeHandle.IsDynamicType()); return RuntimeAugments.GetNonGcStaticFieldData(runtimeTypeHandle); }
public TypeHandle(bool isByRef, RuntimeTypeHandle eeType) { _eeType = eeType.ToEETypePtr(); _isByRef = isByRef; }
public unsafe static bool IsPregeneratedOrTemplateRuntimeTypeHandle(RuntimeTypeHandle rtth) { #if SUPPORTS_NATIVE_METADATA_TYPE_LOADING if (!rtth.IsDynamicType()) return true; if (rtth.ToEETypePtr()->DynamicModule == null) return true; return rtth.ToEETypePtr()->DynamicModule->DynamicTypeSlotDispatchResolve == IntPtr.Zero; #else return true; #endif }
// // Various reflection scenarios (Array.SetValue(), reflection Invoke, delegate DynamicInvoke and FieldInfo.Set()) perform // automatic conveniences such as automatically widening primitive types to fit the destination type. // // This method attempts to collect as much of that logic as possible in place. (This may not be completely possible // as the desktop CLR is not particularly consistent across all these scenarios either.) // // The transforms supported are: // // Value-preserving widenings of primitive integrals and floats. // Enums can be converted to the same or wider underlying primitive. // Primitives can be converted to an enum with the same or wider underlying primitive. // // null converted to default(T) (this is important when T is a valuetype.) // // There is also another transform of T -> Nullable<T>. This method acknowleges that rule but does not actually transform the T. // Rather, the transformation happens naturally when the caller unboxes the value to its final destination. // // This method is targeted by the Delegate ILTransformer. // // public static Object CheckArgument(Object srcObject, RuntimeTypeHandle dstType) { EETypePtr dstEEType = dstType.ToEETypePtr(); return CheckArgument(srcObject, dstEEType, CheckArgumentSemantics.DynamicInvoke); }
public static unsafe void SetInterface(this RuntimeTypeHandle rtth, int interfaceIndex, RuntimeTypeHandle interfaceType) { rtth.ToEETypePtr()->InterfaceMap[interfaceIndex].InterfaceType = interfaceType.ToEETypePtr(); }
internal static object DynamicInvokeBoxedValuetypeReturn(out DynamicInvokeParamLookupType paramLookupType, object boxedValuetype, int index, RuntimeTypeHandle type, DynamicInvokeParamType paramType) { object finalObjectToReturn = boxedValuetype; EETypePtr eeType = type.ToEETypePtr(); bool nullable = RuntimeImports.RhIsNullable(eeType); if (finalObjectToReturn == null || nullable || paramType == DynamicInvokeParamType.Ref) { finalObjectToReturn = RuntimeImports.RhNewObject(eeType); if (boxedValuetype != null) { DynamicInvokeUnboxIntoActualNullable(finalObjectToReturn, boxedValuetype, eeType); } } if (nullable) { if (paramType == DynamicInvokeParamType.Ref) { if (s_nullableCopyBackObjects == null) { s_nullableCopyBackObjects = new object[s_parameters.Length]; } s_nullableCopyBackObjects[index] = finalObjectToReturn; s_parameters[index] = null; } } else { System.Diagnostics.Debug.Assert(finalObjectToReturn != null); if (paramType == DynamicInvokeParamType.Ref) s_parameters[index] = finalObjectToReturn; } paramLookupType = DynamicInvokeParamLookupType.ValuetypeObjectReturned; return finalObjectToReturn; }
public static unsafe void SetGenericArgument(this RuntimeTypeHandle rtth, int argumentIndex, RuntimeTypeHandle argumentType) { rtth.ToEETypePtr()->GenericArguments[argumentIndex].Value = argumentType.ToEETypePtr(); }
public unsafe static void GetFieldAlignmentAndSize(RuntimeTypeHandle fieldType, out int alignment, out int size) { EEType* typePtr = fieldType.ToEETypePtr(); if (typePtr->IsValueType) { size = (int)typePtr->ValueTypeSize; } else { size = IntPtr.Size; } alignment = (int)typePtr->FieldAlignmentRequirement; }
public static unsafe void SetRelatedParameterType(this RuntimeTypeHandle rtth, RuntimeTypeHandle relatedTypeHandle) { rtth.ToEETypePtr()->RelatedParameterType = relatedTypeHandle.ToEETypePtr(); }
private static unsafe object GetDefaultValue(RuntimeTypeHandle thType, int argIndex) { // Group index of 0 indicates there are no default parameters if (s_defaultValueString == null) { throw new ArgumentException(SR.Arg_DefaultValueMissingException); } StringDataParser dataParser = new StringDataParser(s_defaultValueString); // Skip to current argument int curArgIndex = 0; while (curArgIndex != argIndex) { int skip = dataParser.GetInt(); dataParser.Skip(skip); curArgIndex++; } // Discard size of current argument int sizeOfCurrentArg = dataParser.GetInt(); int defaultValueType = dataParser.GetInt(); switch (defaultValueType) { case DefaultParamTypeNone: default: throw new ArgumentException(SR.Arg_DefaultValueMissingException); case DefaultParamTypeString: return dataParser.GetString(); case DefaultParamTypeDefault: if (thType.ToEETypePtr().IsValueType) { if (RuntimeImports.RhIsNullable(thType.ToEETypePtr())) { return null; } else { return RuntimeImports.RhNewObject(thType.ToEETypePtr()); } } else { return null; } case DefaultParamTypeBool: return (dataParser.GetInt() == 1); case DefaultParamTypeChar: return (char)dataParser.GetInt(); case DefaultParamTypeI1: return (sbyte)dataParser.GetInt(); case DefaultParamTypeI2: return (short)dataParser.GetInt(); case DefaultParamTypeI4: return dataParser.GetInt(); case DefaultParamTypeI8: return dataParser.GetLong(); case DefaultParamTypeR4: return dataParser.GetFloat(); case DefaultParamTypeR8: return dataParser.GetDouble(); case DefaultParamTypeDecimal: int[] decimalBits = new int[4]; decimalBits[0] = dataParser.GetInt(); decimalBits[1] = dataParser.GetInt(); decimalBits[2] = dataParser.GetInt(); decimalBits[3] = dataParser.GetInt(); return new Decimal(decimalBits); case DefaultParamTypeDateTime: return new DateTime(dataParser.GetLong()); } }
public static RuntimeTypeHandle CreatePointerEEType(UInt32 hashCodeOfNewType, RuntimeTypeHandle pointeeTypeHandle, TypeDesc pointerType) { TypeBuilderState state = new TypeBuilderState(pointerType); CreateEETypeWorker(typeof(void*).TypeHandle.ToEETypePtr(), hashCodeOfNewType, 0, false, state); Debug.Assert(!state.HalfBakedRuntimeTypeHandle.IsNull()); state.HalfBakedRuntimeTypeHandle.ToEETypePtr()->RelatedParameterType = pointeeTypeHandle.ToEETypePtr(); return state.HalfBakedRuntimeTypeHandle; }
public static Type GetTypeFromHandle(RuntimeTypeHandle handle) => handle.IsNull ? null : GetTypeFromEETypePtr(handle.ToEETypePtr());