Skip to content

Commit a20b31a

Browse files
authored
#76881 internal properties in GetRuntimeProperties are not shown (#77169)
Fixes #76881
1 parent 786d631 commit a20b31a

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

src/libraries/System.Reflection.Extensions/tests/RuntimeReflectionExtensionTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ public void GetRuntimeProperties()
101101
Assert.Contains("CanRead", propertyNames);
102102
Assert.Contains("CanWrite", propertyNames);
103103
Assert.Contains("CanSeek", propertyNames);
104+
105+
List<PropertyInfo> props = typeof(TestClass).GetRuntimeProperties().ToList();
106+
Assert.Equal(2, props.Count);
104107
}
105108

106109
[Fact]
@@ -359,6 +362,16 @@ private class TestDerived : TestBase
359362
public override void Foo() { throw null; }
360363
}
361364

365+
private class TestClassBase
366+
{
367+
internal int TestClassBaseProperty { get; set; }
368+
}
369+
370+
private class TestClass : TestClassBase
371+
{
372+
internal int TestClassProperty { get; set; }
373+
}
374+
362375
abstract class TestTypeBase : IDisposable
363376
{
364377
public abstract bool CanRead { get; }

src/libraries/System.Reflection/tests/AssemblyTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public void ExportedTypes(Type type, bool expected)
148148

149149
[Fact]
150150
[SkipOnPlatform(TestPlatforms.Browser, "entry assembly won't be xunit.console on browser")]
151-
[ActiveIssue("https://github.com/dotnet/runtime/issues/36892", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
151+
[ActiveIssue("https://github.com/dotnet/runtime/issues/36892", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst | TestPlatforms.Android)]
152152
public void GetEntryAssembly()
153153
{
154154
Assert.NotNull(Assembly.GetEntryAssembly());
@@ -881,6 +881,7 @@ public static void AssemblyGetForwardedTypes()
881881

882882
[Fact]
883883
[ActiveIssue("https://github.com/dotnet/runtimelab/issues/155", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
884+
[ActiveIssue("https://github.com/dotnet/runtimelab/issues/77821", TestPlatforms.Android)]
884885
public static void AssemblyGetForwardedTypesLoadFailure()
885886
{
886887
Assembly a = typeof(TypeInForwardedAssembly).Assembly;

src/libraries/tests.proj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@
180180
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.IO.FileSystem.Watcher\tests\System.IO.FileSystem.Watcher.Tests.csproj" />
181181
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.IO.Ports\tests\System.IO.Ports.Tests.csproj" />
182182
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Net.Quic\tests\FunctionalTests\System.Net.Quic.Functional.Tests.csproj" />
183-
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Reflection\tests\System.Reflection.Tests.csproj" />
184183
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime.Serialization.Formatters\tests\System.Runtime.Serialization.Formatters.Tests.csproj" />
185184
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Security.Cryptography.Algorithms\tests\System.Security.Cryptography.Algorithms.Tests.csproj" />
186185
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Security.Cryptography.Csp\tests\System.Security.Cryptography.Csp.Tests.csproj" />

src/mono/mono/metadata/icall.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4057,8 +4057,6 @@ property_accessor_nonpublic (MonoMethod* accessor, gboolean start_klass)
40574057
GPtrArray*
40584058
ves_icall_RuntimeType_GetPropertiesByName_native (MonoQCallTypeHandle type_handle, gchar *propname, guint32 bflags, guint32 mlisttype, MonoError *error)
40594059
{
4060-
// Fetch non-public properties as well because they can hide public properties with the same name in base classes
4061-
bflags |= BFLAGS_NonPublic;
40624060
MonoType *type = type_handle.type;
40634061

40644062
if (m_type_is_byref (type))
@@ -4097,11 +4095,9 @@ ves_icall_RuntimeType_GetPropertiesByName_native (MonoQCallTypeHandle type_handl
40974095
(prop->set && ((prop->set->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC))) {
40984096
if (bflags & BFLAGS_Public)
40994097
match++;
4100-
} else if (bflags & BFLAGS_NonPublic) {
4101-
if (property_accessor_nonpublic(prop->get, startklass == klass) ||
4098+
} else if (property_accessor_nonpublic(prop->get, startklass == klass) ||
41024099
property_accessor_nonpublic(prop->set, startklass == klass)) {
41034100
match++;
4104-
}
41054101
}
41064102
if (!match)
41074103
continue;
@@ -4131,8 +4127,6 @@ ves_icall_RuntimeType_GetPropertiesByName_native (MonoQCallTypeHandle type_handl
41314127
g_hash_table_insert (properties, prop, prop);
41324128
}
41334129
if (!(bflags & BFLAGS_DeclaredOnly) && (klass = m_class_get_parent (klass))) {
4134-
// BFLAGS_NonPublic should be excluded for base classes
4135-
bflags &= ~BFLAGS_NonPublic;
41364130
goto handle_parent;
41374131
}
41384132

0 commit comments

Comments
 (0)