diff --git a/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj
index 1075a708b8bbb3..bc40c0e4830852 100644
--- a/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj
+++ b/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj
@@ -155,7 +155,6 @@
-
@@ -194,6 +193,7 @@
+
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs
index a45d81d4b2342a..cb7bd41495f6dc 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs
@@ -322,7 +322,7 @@ public override bool IsDefined(Type attributeType, bool inherit)
public override IList GetCustomAttributesData()
{
- return CustomAttributeData.GetCustomAttributesInternal(this);
+ return RuntimeCustomAttributeData.GetCustomAttributesInternal(this);
}
internal static RuntimeAssembly InternalLoad(string assemblyName, ref StackCrawlMark stackMark, AssemblyLoadContext? assemblyLoadContext = null)
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeConstructorInfo.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeConstructorInfo.cs
index 21bcf10557f9be..1af3d758916f0c 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeConstructorInfo.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeConstructorInfo.cs
@@ -198,7 +198,7 @@ public override bool IsDefined(Type attributeType, bool inherit)
public override IList GetCustomAttributesData()
{
- return CustomAttributeData.GetCustomAttributesInternal(this);
+ return RuntimeCustomAttributeData.GetCustomAttributesInternal(this);
}
#endregion
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs
similarity index 97%
rename from src/coreclr/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs
rename to src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs
index 96c062f4885dc6..4bdc413dfc2f49 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs
@@ -12,7 +12,7 @@
namespace System.Reflection
{
- public partial class CustomAttributeData
+ internal sealed class RuntimeCustomAttributeData : CustomAttributeData
{
#region Internal Static Members
internal static IList GetCustomAttributesInternal(RuntimeType target)
@@ -103,7 +103,7 @@ private static IList GetCombinedList(IList GetCustomAttributes(RuntimeModule modu
CustomAttributeData[] customAttributes = new CustomAttributeData[records.Length];
for (int i = 0; i < records.Length; i++)
- customAttributes[i] = new CustomAttributeData(module, records[i].tkCtor, in records[i].blob);
+ customAttributes[i] = new RuntimeCustomAttributeData(module, records[i].tkCtor, in records[i].blob);
return Array.AsReadOnly(customAttributes);
}
@@ -262,17 +262,13 @@ internal static CustomAttributeTypedArgument Filter(IList a
private IList m_namedArgs = null!;
#region Constructor
- protected CustomAttributeData()
- {
- }
-
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075:UnrecognizedReflectionPattern",
Justification = "Property setters and fields which are accessed by any attribute instantiation which is present in the code linker has analyzed." +
"As such enumerating all fields and properties may return different results after trimming" +
"but all those which are needed to actually have data will be there.")]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern",
Justification = "We're getting a MethodBase of a constructor that we found in the metadata. The attribute constructor won't be trimmed.")]
- private CustomAttributeData(RuntimeModule scope, MetadataToken caCtorToken, in ConstArray blob)
+ private RuntimeCustomAttributeData(RuntimeModule scope, MetadataToken caCtorToken, in ConstArray blob)
{
m_scope = scope;
m_ctor = (RuntimeConstructorInfo)RuntimeType.GetMethodBase(scope, caCtorToken)!;
@@ -301,7 +297,7 @@ private CustomAttributeData(RuntimeModule scope, MetadataToken caCtorToken, in C
#endregion
#region Pseudo Custom Attribute Constructor
- internal CustomAttributeData(Attribute attribute)
+ internal RuntimeCustomAttributeData(Attribute attribute)
{
if (attribute is DllImportAttribute dllImportAttribute)
Init(dllImportAttribute);
@@ -415,9 +411,9 @@ private void Init(object pca)
#endregion
#region Public Members
- public virtual ConstructorInfo Constructor => m_ctor;
+ public override ConstructorInfo Constructor => m_ctor;
- public virtual IList ConstructorArguments
+ public override IList ConstructorArguments
{
get
{
@@ -439,7 +435,7 @@ public virtual IList ConstructorArguments
}
}
- public virtual IList NamedArguments
+ public override IList NamedArguments
{
get
{
@@ -557,17 +553,6 @@ private static RuntimeType ResolveType(RuntimeModule scope, string typeName)
}
#endregion
- private static object CanonicalizeValue(object value)
- {
- Debug.Assert(value is not null);
-
- if (value.GetType().IsEnum)
- {
- return ((Enum)value).GetValue();
- }
- return value;
- }
-
internal CustomAttributeTypedArgument(RuntimeModule scope, CustomAttributeEncodedArgument encodedArg)
{
CustomAttributeEncoding encodedType = encodedArg.CustomAttributeType.EncodedType;
@@ -577,22 +562,22 @@ internal CustomAttributeTypedArgument(RuntimeModule scope, CustomAttributeEncode
if (encodedType == CustomAttributeEncoding.Enum)
{
- m_argumentType = ResolveType(scope, encodedArg.CustomAttributeType.EnumName!);
- m_value = EncodedValueToRawValue(encodedArg.PrimitiveValue, encodedArg.CustomAttributeType.EncodedEnumType);
+ _argumentType = ResolveType(scope, encodedArg.CustomAttributeType.EnumName!);
+ _value = EncodedValueToRawValue(encodedArg.PrimitiveValue, encodedArg.CustomAttributeType.EncodedEnumType);
}
else if (encodedType == CustomAttributeEncoding.String)
{
- m_argumentType = typeof(string);
- m_value = encodedArg.StringValue;
+ _argumentType = typeof(string);
+ _value = encodedArg.StringValue;
}
else if (encodedType == CustomAttributeEncoding.Type)
{
- m_argumentType = typeof(Type);
+ _argumentType = typeof(Type);
- m_value = null;
+ _value = null;
if (encodedArg.StringValue is not null)
- m_value = ResolveType(scope, encodedArg.StringValue);
+ _value = ResolveType(scope, encodedArg.StringValue);
}
else if (encodedType == CustomAttributeEncoding.Array)
{
@@ -608,11 +593,11 @@ internal CustomAttributeTypedArgument(RuntimeModule scope, CustomAttributeEncode
elementType = CustomAttributeEncodingToType(encodedType);
}
- m_argumentType = elementType.MakeArrayType();
+ _argumentType = elementType.MakeArrayType();
if (encodedArg.ArrayValue is null)
{
- m_value = null;
+ _value = null;
}
else
{
@@ -620,13 +605,13 @@ internal CustomAttributeTypedArgument(RuntimeModule scope, CustomAttributeEncode
for (int i = 0; i < arrayValue.Length; i++)
arrayValue[i] = new CustomAttributeTypedArgument(scope, encodedArg.ArrayValue[i]);
- m_value = Array.AsReadOnly(arrayValue);
+ _value = Array.AsReadOnly(arrayValue);
}
}
else
{
- m_argumentType = CustomAttributeEncodingToType(encodedType);
- m_value = EncodedValueToRawValue(encodedArg.PrimitiveValue, encodedType);
+ _argumentType = CustomAttributeEncodingToType(encodedType);
+ _value = EncodedValueToRawValue(encodedArg.PrimitiveValue, encodedType);
}
}
}
@@ -1168,7 +1153,7 @@ private static void AddCustomAttributes(
// The derivedAttributes list must be passed by value so that it is not modified with the discovered attributes
RuntimeType.ListBuilder