Skip to content

Getting Enum fields/attributes in trimmed and AOT'd applications #105506

Closed
@eerhardt

Description

@eerhardt

Similar to #97737, we should support more scenarios where we know a Type is an Enum type without emitting warnings.

The example scenario comes from https://github.com/microsoft/OpenAPI.NET/pull/1717/files#diff-c59c9153ccf5e00142826d1c5e4d3d92470aac0bc740a302a23557432141277c

        public static T GetAttributeOfType<T>(this Enum enumValue) where T : Attribute
        {
            var type = enumValue.GetType();
            var memInfo = type.GetField(enumValue.ToString(), BindingFlags.Public | BindingFlags.Static);

This code shouldn't warn because type is guaranteed to be an Enum type.

This scenario was explicitly not supported in #105351. We should support it.

cc @sbomer @MichalStrehovsky

Metadata

Metadata

Assignees

Type

No type

Projects

Status

No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions