From 25e84d3ede510e052bf24c80bc3ce92f7c784e0f Mon Sep 17 00:00:00 2001 From: Jan Dupej <109523496+jandupej@users.noreply.github.com> Date: Thu, 12 Jan 2023 14:24:27 +0100 Subject: [PATCH] [mono] Fixed getting namespace names of array types. (#80426) * [mono] Fixed getting namespace names of array types. #42633 * [mono] Namespace getter icall of Type, code style. * Reenabled TypeInfoTests.Namespace for Mono. * [mono] Namespace for array types now works also for jagged arrays. * [mono] Fixed Type.Namespace for enums. * [mono] Fixed failing Microsoft.XmlSerializer.Generator.Tests.SgenCommandTest. * Adding cases to TypeInfoTests.Namespace test. --- src/libraries/System.Reflection/tests/TypeInfoTests.cs | 7 ++++++- src/mono/mono/metadata/icall.c | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Reflection/tests/TypeInfoTests.cs b/src/libraries/System.Reflection/tests/TypeInfoTests.cs index 3e6cd0deeffbc..f58ce44a4e43e 100644 --- a/src/libraries/System.Reflection/tests/TypeInfoTests.cs +++ b/src/libraries/System.Reflection/tests/TypeInfoTests.cs @@ -1474,7 +1474,8 @@ public void IsVisible(Type type, bool expected) [InlineData(typeof(int), "System")] [InlineData(typeof(TI_BaseClass[]), "System.Reflection.Tests")] [InlineData(typeof(TI_BaseClass.PublicNestedClass1[]), "System.Reflection.Tests")] - [ActiveIssue("https://github.com/dotnet/runtime/issues/42633", TestRuntimes.Mono)] + [InlineData(typeof(TI_BaseClass.PublicNestedClass1[][]), "System.Reflection.Tests")] + [InlineData(typeof(TI_Struct*), "System.Reflection.Tests")] public void Namespace(Type type, string expected) { Assert.Equal(expected, type.GetTypeInfo().Namespace); @@ -1864,6 +1865,10 @@ public class ClassWithExplicitStructLayout public short y; } } + public struct TI_Struct + { + public int _field; + } public class TI_BaseClass { static TI_BaseClass() { } diff --git a/src/mono/mono/metadata/icall.c b/src/mono/mono/metadata/icall.c index 8c00f3792904d..f70410a4b032b 100644 --- a/src/mono/mono/metadata/icall.c +++ b/src/mono/mono/metadata/icall.c @@ -2988,6 +2988,12 @@ ves_icall_RuntimeType_GetNamespace (MonoQCallTypeHandle type_handle, MonoObjectH { MonoType *type = type_handle.type; MonoClass *klass = mono_class_from_mono_type_internal (type); + + MonoClass *elem; + while (!m_class_is_enumtype (klass) && + !mono_class_is_nullable (klass) && + (klass != (elem = m_class_get_element_class (klass)))) + klass = elem; MonoClass *klass_nested_in; while ((klass_nested_in = m_class_get_nested_in (klass)))