Skip to content

Commit

Permalink
#76881 internal properties in GetRuntimeProperties are not shown (#77169
Browse files Browse the repository at this point in the history
)

Fixes #76881
  • Loading branch information
mkhamoyan authored Nov 3, 2022
1 parent 786d631 commit a20b31a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ public void GetRuntimeProperties()
Assert.Contains("CanRead", propertyNames);
Assert.Contains("CanWrite", propertyNames);
Assert.Contains("CanSeek", propertyNames);

List<PropertyInfo> props = typeof(TestClass).GetRuntimeProperties().ToList();
Assert.Equal(2, props.Count);
}

[Fact]
Expand Down Expand Up @@ -359,6 +362,16 @@ private class TestDerived : TestBase
public override void Foo() { throw null; }
}

private class TestClassBase
{
internal int TestClassBaseProperty { get; set; }
}

private class TestClass : TestClassBase
{
internal int TestClassProperty { get; set; }
}

abstract class TestTypeBase : IDisposable
{
public abstract bool CanRead { get; }
Expand Down
3 changes: 2 additions & 1 deletion src/libraries/System.Reflection/tests/AssemblyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void ExportedTypes(Type type, bool expected)

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

[Fact]
[ActiveIssue("https://github.com/dotnet/runtimelab/issues/155", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
[ActiveIssue("https://github.com/dotnet/runtimelab/issues/77821", TestPlatforms.Android)]
public static void AssemblyGetForwardedTypesLoadFailure()
{
Assembly a = typeof(TypeInForwardedAssembly).Assembly;
Expand Down
1 change: 0 additions & 1 deletion src/libraries/tests.proj
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.IO.FileSystem.Watcher\tests\System.IO.FileSystem.Watcher.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.IO.Ports\tests\System.IO.Ports.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Net.Quic\tests\FunctionalTests\System.Net.Quic.Functional.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Reflection\tests\System.Reflection.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime.Serialization.Formatters\tests\System.Runtime.Serialization.Formatters.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Security.Cryptography.Algorithms\tests\System.Security.Cryptography.Algorithms.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Security.Cryptography.Csp\tests\System.Security.Cryptography.Csp.Tests.csproj" />
Expand Down
8 changes: 1 addition & 7 deletions src/mono/mono/metadata/icall.c
Original file line number Diff line number Diff line change
Expand Up @@ -4057,8 +4057,6 @@ property_accessor_nonpublic (MonoMethod* accessor, gboolean start_klass)
GPtrArray*
ves_icall_RuntimeType_GetPropertiesByName_native (MonoQCallTypeHandle type_handle, gchar *propname, guint32 bflags, guint32 mlisttype, MonoError *error)
{
// Fetch non-public properties as well because they can hide public properties with the same name in base classes
bflags |= BFLAGS_NonPublic;
MonoType *type = type_handle.type;

if (m_type_is_byref (type))
Expand Down Expand Up @@ -4097,11 +4095,9 @@ ves_icall_RuntimeType_GetPropertiesByName_native (MonoQCallTypeHandle type_handl
(prop->set && ((prop->set->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC))) {
if (bflags & BFLAGS_Public)
match++;
} else if (bflags & BFLAGS_NonPublic) {
if (property_accessor_nonpublic(prop->get, startklass == klass) ||
} else if (property_accessor_nonpublic(prop->get, startklass == klass) ||
property_accessor_nonpublic(prop->set, startklass == klass)) {
match++;
}
}
if (!match)
continue;
Expand Down Expand Up @@ -4131,8 +4127,6 @@ ves_icall_RuntimeType_GetPropertiesByName_native (MonoQCallTypeHandle type_handl
g_hash_table_insert (properties, prop, prop);
}
if (!(bflags & BFLAGS_DeclaredOnly) && (klass = m_class_get_parent (klass))) {
// BFLAGS_NonPublic should be excluded for base classes
bflags &= ~BFLAGS_NonPublic;
goto handle_parent;
}

Expand Down

0 comments on commit a20b31a

Please sign in to comment.