Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop special casing reflected-on internals #85963

Merged
merged 2 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -804,10 +804,6 @@
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:System.Diagnostics.DebuggerGuidedStepThroughAttribute</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:System.Diagnostics.Tracing.PropertyValue</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:System.MDArray</Target>
Expand Down Expand Up @@ -872,10 +868,6 @@
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:System.Reflection.RuntimeAssemblyName</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:System.Resources.RuntimeResourceSet</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:System.Runtime.CompilerServices.EagerStaticClassConstructionAttribute</Target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@ namespace System.Diagnostics.Tracing
///
/// To get the value of a property quickly, use a delegate produced by <see cref="PropertyValue.GetPropertyGetter(PropertyInfo)"/>.
/// </summary>
#if NATIVEAOT
[CLSCompliant(false)]
public // On NativeAOT, this must be public to prevent it from getting reflection blocked.
#else
internal
#endif
readonly unsafe struct PropertyValue
internal readonly unsafe struct PropertyValue
{
/// <summary>
/// Union of well-known value types, to avoid boxing those types.
Expand Down Expand Up @@ -202,12 +196,7 @@ private static Func<PropertyValue, PropertyValue> GetReferenceTypePropertyGetter
return helper.GetPropertyGetter(property);
}

#if NATIVEAOT
public // On NativeAOT, this must be public to prevent it from getting reflection blocked.
#else
private
#endif
abstract class TypeHelper
private abstract class TypeHelper
{
public abstract Func<PropertyValue, PropertyValue> GetPropertyGetter(PropertyInfo property);

Expand All @@ -219,12 +208,7 @@ protected static Delegate GetGetMethod(PropertyInfo property, Type propertyType)
}
}

#if NATIVEAOT
public // On NativeAOT, this must be public to prevent it from getting reflection blocked.
#else
private
#endif
sealed class ReferenceTypeHelper<TContainer> : TypeHelper where TContainer : class
private sealed class ReferenceTypeHelper<TContainer> : TypeHelper where TContainer : class
{
private static Func<TContainer, TProperty> GetGetMethod<TProperty>(PropertyInfo property) where TProperty : struct =>
property.GetMethod!.CreateDelegate<Func<TContainer, TProperty>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,7 @@ namespace System.Resources
// into smaller chunks, each of size sqrt(n), would be substantially better for
// resource files containing thousands of resources.
//
#if NATIVEAOT
public // On NativeAOT, this must be public to prevent it from getting reflection blocked.
#else
internal
#endif
sealed class RuntimeResourceSet : ResourceSet, IEnumerable
internal sealed class RuntimeResourceSet : ResourceSet, IEnumerable
{
// Cache for resources. Key is the resource name, which can be cached
// for arbitrarily long times, since the object is usually a string
Expand Down
4 changes: 4 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/SR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ internal static partial class SR
private static readonly object _lock = new object();
private static List<string>? _currentlyLoading;
private static int _infinitelyRecursingCount;
#if SYSTEM_PRIVATE_CORELIB
private static bool _resourceManagerInited;
#endif

private static string InternalGetResourceString(string key)
{
Expand Down Expand Up @@ -72,6 +74,7 @@ private static string InternalGetResourceString(string key)

_currentlyLoading ??= new List<string>();

#if SYSTEM_PRIVATE_CORELIB
// Call class constructors preemptively, so that we cannot get into an infinite
// loop constructing a TypeInitializationException. If this were omitted,
// we could get the Infinite recursion assert above by failing type initialization
Expand All @@ -84,6 +87,7 @@ private static string InternalGetResourceString(string key)
RuntimeHelpers.RunClassConstructor(typeof(BinaryReader).TypeHandle);
_resourceManagerInited = true;
}
#endif

_currentlyLoading.Add(key); // Push

Expand Down