-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Closed
Copy link
Labels
Description
Description
Given an attribute that take an object
as a parameter, when using an Enum it gets converted to an int
before being passed to the constructor during AOT
Reproduction Steps
using System.ComponentModel;
using System.Reflection;
var defaultValue = typeof(MyTeam)
.GetProperty("Quarterback")!
.GetCustomAttribute<DefaultValueAttribute>()!.Value!;
var customValue = typeof(MyTeam)
.GetProperty("Backup")!
.GetCustomAttribute<MyCustomAttribute>()!.Value!;
Console.WriteLine($"{defaultValue.GetType()} {defaultValue}");
Console.WriteLine($"{customValue.GetType()} {customValue}");
internal enum Quarterbacks { Teddy, Lamar, Malik, Stefan }
internal class MyTeam
{
[DefaultValue(Quarterbacks.Lamar)]
public Quarterbacks Quarterback { get; set; }
[MyCustom(Quarterbacks.Teddy)]
public Quarterbacks Backup { get; set; }
}
internal class MyCustomAttribute(object value) : Attribute
{
public object Value => value;
}
Expected behavior
Quarterbacks Lamar
Quarterbacks Teddy
Actual behavior
System.Int32 1
System.Int32 0
Regression?
Not sure
Known Workarounds
For custom attributes, using a generic attribute will now work. But that doesn't help when wanting to use an existing one like DefaultAttribute
Configuration
- .net 8
- Windows 11
- x64
Not sure
Other information
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
No status