+ if (mono_reflection_is_usertype (ref)) {
+ MONO_HANDLE_ASSIGN (ref, mono_reflection_type_get_underlying_system_type (ref, error));
+ if (!is_ok (error) || MONO_HANDLE_IS_NULL (ref) || mono_reflection_is_usertype (ref))
+ goto leave;
+ t = MONO_HANDLE_GETVAL (ref, type);
+ if (t) {
+ result = t;
+ goto leave;
+ }
+ }
+
+ MonoClass *klass = mono_handle_class (ref);
+
+ if (is_sre_array (klass)) {
+ MonoReflectionArrayTypeHandle sre_array = MONO_HANDLE_CAST (MonoReflectionArrayType, ref);
+ MonoReflectionTypeHandle ref_element = MONO_HANDLE_NEW_GET (MonoReflectionType, sre_array, element_type);
+ MonoType *base = mono_reflection_type_handle_mono_type (ref_element, error);
+ if (!is_ok (error))
+ goto leave;
+ g_assert (base);
+ gint32 rank = MONO_HANDLE_GETVAL (sre_array, rank);
+ MonoClass *eclass = mono_class_from_mono_type (base);
+ result = mono_image_new0 (eclass->image, MonoType, 1);
+ if (rank == 0) {
+ result->type = MONO_TYPE_SZARRAY;
+ result->data.klass = eclass;
+ } else {
+ MonoArrayType *at = (MonoArrayType *)mono_image_alloc0 (eclass->image, sizeof (MonoArrayType));
+ result->type = MONO_TYPE_ARRAY;
+ result->data.array = at;
+ at->eklass = eclass;
+ at->rank = rank;
+ }
+ MONO_HANDLE_SETVAL (ref, type, MonoType*, result);
+ } else if (is_sre_byref (klass)) {
+ MonoReflectionDerivedTypeHandle sre_byref = MONO_HANDLE_CAST (MonoReflectionDerivedType, ref);
+ MonoReflectionTypeHandle ref_element = MONO_HANDLE_NEW_GET (MonoReflectionType, sre_byref, element_type);
+ MonoType *base = mono_reflection_type_handle_mono_type (ref_element, error);
+ if (!is_ok (error))
+ goto leave;
+ g_assert (base);
+ result = &mono_class_from_mono_type (base)->this_arg;
+ MONO_HANDLE_SETVAL (ref, type, MonoType*, result);
+ } else if (is_sre_pointer (klass)) {
+ MonoReflectionDerivedTypeHandle sre_pointer = MONO_HANDLE_CAST (MonoReflectionDerivedType, ref);
+ MonoReflectionTypeHandle ref_element = MONO_HANDLE_NEW_GET (MonoReflectionType, sre_pointer, element_type);
+ MonoType *base = mono_reflection_type_handle_mono_type (ref_element, error);
+ if (!is_ok (error))
+ goto leave;
+ g_assert (base);
+ result = &mono_ptr_class_get (base)->byval_arg;
+ MONO_HANDLE_SETVAL (ref, type, MonoType*, result);
+ } else if (is_sre_generic_instance (klass)) {
+ result = reflection_instance_handle_mono_type (MONO_HANDLE_CAST (MonoReflectionGenericClass, ref), error);
+ } else if (is_sre_gparam_builder (klass)) {
+ result = reflection_param_handle_mono_type (MONO_HANDLE_CAST (MonoReflectionGenericParam, ref), error);