@@ -269,6 +269,36 @@ private static partial void CreateInstanceForAnotherGenericParameter(
269
269
int cTypeHandles ,
270
270
ObjectHandleOnStack instantiatedObject ) ;
271
271
272
+ internal static unsafe object InternalAlloc ( MethodTable * pMT )
273
+ {
274
+ object ? result = null ;
275
+ InternalAlloc ( pMT , ObjectHandleOnStack . Create ( ref result ) ) ;
276
+ return result ! ;
277
+ }
278
+
279
+ internal static object InternalAlloc ( RuntimeType type )
280
+ {
281
+ Debug . Assert ( ! type . GetNativeTypeHandle ( ) . IsTypeDesc ) ;
282
+ object result = InternalAlloc ( type . GetNativeTypeHandle ( ) . AsMethodTable ( ) ) ;
283
+ GC . KeepAlive ( type ) ;
284
+ return result ;
285
+ }
286
+
287
+ [ LibraryImport ( RuntimeHelpers . QCall , EntryPoint = "RuntimeTypeHandle_InternalAlloc" ) ]
288
+ private static unsafe partial void InternalAlloc ( MethodTable * pMT , ObjectHandleOnStack result ) ;
289
+
290
+ internal static object InternalAllocNoChecks ( RuntimeType type )
291
+ {
292
+ Debug . Assert ( ! type . GetNativeTypeHandle ( ) . IsTypeDesc ) ;
293
+ object ? result = null ;
294
+ InternalAllocNoChecks ( type . GetNativeTypeHandle ( ) . AsMethodTable ( ) , ObjectHandleOnStack . Create ( ref result ) ) ;
295
+ GC . KeepAlive ( type ) ;
296
+ return result ! ;
297
+ }
298
+
299
+ [ LibraryImport ( RuntimeHelpers . QCall , EntryPoint = "RuntimeTypeHandle_InternalAllocNoChecks" ) ]
300
+ private static unsafe partial void InternalAllocNoChecks ( MethodTable * pMT , ObjectHandleOnStack result ) ;
301
+
272
302
/// <summary>
273
303
/// Given a RuntimeType, returns information about how to activate it via calli
274
304
/// semantics. This method will ensure the type object is fully initialized within
@@ -1026,14 +1056,59 @@ internal static MdUtf8String GetUtf8Name(RuntimeMethodHandleInternal method)
1026
1056
1027
1057
[ DebuggerStepThrough ]
1028
1058
[ DebuggerHidden ]
1029
- [ MethodImpl ( MethodImplOptions . InternalCall ) ]
1030
- internal static extern object ? InvokeMethod ( object ? target , void * * arguments , Signature sig , bool isConstructor ) ;
1059
+ [ LibraryImport ( RuntimeHelpers . QCall , EntryPoint = "RuntimeMethodHandle_InvokeMethod" ) ]
1060
+ private static partial void InvokeMethod ( ObjectHandleOnStack target , void * * arguments , ObjectHandleOnStack sig , Interop . BOOL isConstructor , ObjectHandleOnStack result ) ;
1031
1061
1032
- [ MethodImpl ( MethodImplOptions . InternalCall ) ]
1033
- internal static extern object ? ReboxFromNullable ( object ? src ) ;
1062
+ [ DebuggerStepThrough ]
1063
+ [ DebuggerHidden ]
1064
+ internal static object ? InvokeMethod ( object ? target , void * * arguments , Signature sig , bool isConstructor )
1065
+ {
1066
+ object ? result = null ;
1067
+ InvokeMethod (
1068
+ ObjectHandleOnStack . Create ( ref target ) ,
1069
+ arguments ,
1070
+ ObjectHandleOnStack . Create ( ref sig ) ,
1071
+ isConstructor ? Interop . BOOL . TRUE : Interop . BOOL . FALSE ,
1072
+ ObjectHandleOnStack . Create ( ref result ) ) ;
1073
+ return result ;
1074
+ }
1034
1075
1035
- [ MethodImpl ( MethodImplOptions . InternalCall ) ]
1036
- internal static extern object ReboxToNullable ( object ? src , RuntimeType destNullableType ) ;
1076
+ /// <summary>
1077
+ /// For a true boxed Nullable{T}, re-box to a boxed {T} or null, otherwise just return the input.
1078
+ /// </summary>
1079
+ internal static object ? ReboxFromNullable ( object ? src )
1080
+ {
1081
+ // If src is null or not NullableOfT, just return that state.
1082
+ if ( src is null )
1083
+ {
1084
+ return null ;
1085
+ }
1086
+
1087
+ MethodTable * pMT = RuntimeHelpers . GetMethodTable ( src ) ;
1088
+ if ( ! pMT ->IsNullable )
1089
+ {
1090
+ return src ;
1091
+ }
1092
+
1093
+ return CastHelpers . ReboxFromNullable ( pMT , src ) ;
1094
+ }
1095
+
1096
+ /// <summary>
1097
+ /// Convert a boxed value of {T} (which is either {T} or null) to a true boxed Nullable{T}.
1098
+ /// </summary>
1099
+ internal static object ReboxToNullable ( object ? src , RuntimeType destNullableType )
1100
+ {
1101
+ Debug . Assert ( destNullableType . IsNullableOfT ) ;
1102
+ MethodTable * pMT = destNullableType . GetNativeTypeHandle ( ) . AsMethodTable ( ) ;
1103
+ object obj = RuntimeTypeHandle . InternalAlloc ( pMT ) ;
1104
+ GC . KeepAlive ( destNullableType ) ; // The obj instance will keep the type alive.
1105
+
1106
+ CastHelpers . Unbox_Nullable (
1107
+ ref obj . GetRawData ( ) ,
1108
+ pMT ,
1109
+ src ) ;
1110
+ return obj ;
1111
+ }
1037
1112
1038
1113
[ LibraryImport ( RuntimeHelpers . QCall , EntryPoint = "RuntimeMethodHandle_GetMethodInstantiation" ) ]
1039
1114
private static partial void GetMethodInstantiation ( RuntimeMethodHandleInternal method , ObjectHandleOnStack types , Interop . BOOL fAsRuntimeTypeArray ) ;
0 commit comments