[runtime] Implement mono_class_get_nullable_param for CoreCLR. (#11531)
This commit is contained in:
Родитель
95dfc4fa39
Коммит
64e19d2d34
|
@ -533,6 +533,14 @@ mono_class_get_element_class (MonoClass *klass)
|
|||
return rv;
|
||||
}
|
||||
|
||||
MonoClass *
|
||||
mono_class_get_nullable_param (MonoClass * klass)
|
||||
{
|
||||
MonoClass *rv = xamarin_bridge_get_nullable_element_type (klass);
|
||||
LOG_CORECLR (stderr, "%s (%p) => %p\n", __func__, klass, rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool
|
||||
xamarin_is_class_nsobject (MonoClass *cls)
|
||||
{
|
||||
|
|
|
@ -519,6 +519,14 @@
|
|||
OnlyCoreCLR = true,
|
||||
},
|
||||
|
||||
new XDelegate ("MonoObject *", "MonoObject *", "xamarin_bridge_get_nullable_element_type",
|
||||
"MonoObject *", "MonoObject *", "typeobj"
|
||||
) {
|
||||
WrappedManagedFunction = "GetNullableElementType",
|
||||
OnlyDynamicUsage = false,
|
||||
OnlyCoreCLR = true,
|
||||
},
|
||||
|
||||
new XDelegate ("bool", "bool", "xamarin_bridge_is_delegate",
|
||||
"MonoObject *", "MonoObject *", "typeobj"
|
||||
) {
|
||||
|
|
|
@ -96,7 +96,9 @@
|
|||
|
||||
new Export (true, "MonoClass *", "mono_class_get_nullable_param",
|
||||
"MonoClass *", "klass"
|
||||
),
|
||||
) {
|
||||
HasCoreCLRBridgeFunction = true,
|
||||
},
|
||||
#endregion
|
||||
|
||||
#region metadata/debug-helpers.h
|
||||
|
|
|
@ -931,6 +931,7 @@ exception_handling:
|
|||
xamarin_mono_object_release (&nativeType);
|
||||
xamarin_mono_object_release (&nativeElementType);
|
||||
xamarin_mono_object_release (&managedElementType);
|
||||
xamarin_mono_object_release (&nullableManagedType);
|
||||
|
||||
return convertedValue;
|
||||
}
|
||||
|
@ -1019,6 +1020,7 @@ exception_handling:
|
|||
xamarin_mono_object_release (&nativeType);
|
||||
xamarin_mono_object_release (&nativeElementType);
|
||||
xamarin_mono_object_release (&managedElementType);
|
||||
xamarin_mono_object_release (&nullableManagedType);
|
||||
|
||||
return convertedValue;
|
||||
}
|
||||
|
|
|
@ -151,6 +151,13 @@ namespace ObjCRuntime {
|
|||
return (MonoObject*) GetMonoObject (type.GetElementType ());
|
||||
}
|
||||
|
||||
static unsafe MonoObject* GetNullableElementType (MonoObject* typeobj)
|
||||
{
|
||||
var type = (Type) GetMonoObjectTarget (typeobj);
|
||||
var elementType = type.GetGenericArguments () [0];
|
||||
return (MonoObject*) GetMonoObject (elementType);
|
||||
}
|
||||
|
||||
static IntPtr CreateGCHandle (IntPtr gchandle, GCHandleType type)
|
||||
{
|
||||
// It's valid to create a GCHandle to a null value.
|
||||
|
|
|
@ -4474,6 +4474,7 @@ namespace Registrar {
|
|||
underlyingManagedType = GetNullableType (managedType);
|
||||
sb.AppendLine ($"{classVariableName} = xamarin_get_nullable_type ({managedClassExpression}, &exception_gchandle);");
|
||||
sb.AppendLine ($"if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
|
||||
cleanup.AppendLine ($"xamarin_mono_object_release (&{classVariableName});");
|
||||
} else {
|
||||
sb.AppendLine ($"{classVariableName} = {managedClassExpression};");
|
||||
}
|
||||
|
@ -4565,6 +4566,7 @@ namespace Registrar {
|
|||
underlyingManagedType = GetNullableType (managedType);
|
||||
sb.AppendLine ($"{classVariableName} = xamarin_get_nullable_type ({managedClassExpression}, &exception_gchandle);");
|
||||
sb.AppendLine ($"if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
|
||||
cleanup.AppendLine ($"xamarin_mono_object_release (&{classVariableName});");
|
||||
} else {
|
||||
sb.AppendLine ($"{classVariableName} = {managedClassExpression};");
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче