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

Don't look at custom attributes for field constants #80991

Merged
merged 1 commit into from
Jan 22, 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 @@ -139,7 +139,7 @@ public sealed override RuntimeFieldHandle FieldHandle

protected sealed override bool GetDefaultValueIfAvailable(bool raw, out object? defaultValue)
{
return DefaultValueParser.GetDefaultValueIfAny(_reader, _field.DefaultValue, FieldType, CustomAttributes, raw, out defaultValue);
return DefaultValueParser.GetDefaultValueFromConstantIfAny(_reader, _field.DefaultValue, FieldType, raw, out defaultValue);
}

protected sealed override FieldAccessor TryGetFieldAccessor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace System.Reflection.Runtime.General.NativeFormat
{
internal static class DefaultValueParser
{
public static bool GetDefaultValueIfAny(MetadataReader reader, Handle constantHandle, Type declaredType, IEnumerable<CustomAttributeData> customAttributes, bool raw, out object? defaultValue)
public static bool GetDefaultValueFromConstantIfAny(MetadataReader reader, Handle constantHandle, Type declaredType, bool raw, out object? defaultValue)
{
if (!(constantHandle.IsNull(reader)))
{
Expand All @@ -18,6 +18,12 @@ public static bool GetDefaultValueIfAny(MetadataReader reader, Handle constantHa
return true;
}

defaultValue = null;
return false;
}

public static bool GetDefaultValueFromAttributeIfAny(IEnumerable<CustomAttributeData> customAttributes, bool raw, out object? defaultValue)
{
if (Helpers.GetCustomAttributeDefaultValueIfAny(customAttributes, raw, out defaultValue))
return true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public sealed override int MetadataToken

protected sealed override bool GetDefaultValueIfAvailable(bool raw, out object? defaultValue)
{
return DefaultValueParser.GetDefaultValueIfAny(Reader, _parameter.DefaultValue, ParameterType, CustomAttributes, raw, out defaultValue);
return DefaultValueParser.GetDefaultValueFromConstantIfAny(Reader, _parameter.DefaultValue, ParameterType, raw, out defaultValue)
|| DefaultValueParser.GetDefaultValueFromAttributeIfAny(CustomAttributes, raw, out defaultValue);
}

private readonly MethodHandle _methodHandle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ protected sealed override QSignatureTypeHandle PropertyTypeHandle

protected sealed override bool GetDefaultValueIfAny(bool raw, out object? defaultValue)
{
return DefaultValueParser.GetDefaultValueIfAny(_reader, _property.DefaultValue, PropertyType, CustomAttributes, raw, out defaultValue);
return DefaultValueParser.GetDefaultValueFromConstantIfAny(_reader, _property.DefaultValue, PropertyType, raw, out defaultValue)
|| DefaultValueParser.GetDefaultValueFromAttributeIfAny(CustomAttributes, raw, out defaultValue);
}

protected sealed override RuntimeNamedMethodInfo GetPropertyMethod(PropertyMethodSemantics whichMethod)
Expand Down