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

[feature/dataflow] Allow DynamicallyAccessedMembers on generic types #1086

Closed
eerhardt opened this issue Apr 9, 2020 · 0 comments · Fixed by #1245
Closed

[feature/dataflow] Allow DynamicallyAccessedMembers on generic types #1086

eerhardt opened this issue Apr 9, 2020 · 0 comments · Fixed by #1245
Assignees

Comments

@eerhardt
Copy link
Member

eerhardt commented Apr 9, 2020

In System.Text.Json, we have code like the following

        internal static void Serialize<T>(
            Utf8JsonWriter writer,
            T value,
            JsonSerializerOptions options,
            ref WriteStack state,
            string? propertyName = null)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            JsonConverter jsonConverter = state.Current.InitializeReEntry(typeof(T), options, propertyName);
            bool success = jsonConverter.TryWriteAsObject(writer, value, options, ref state);
            Debug.Assert(success);
        }

Here the type T needs to be annotated with DynamicallyAccessedMemberKinds.Properties because InitializeReEntry will eventually need to access all the properties on T. However, the linker currently doesn't recognize when I try to annotate the method like the following:

        internal static void Serialize<[DynamicallyAccessedMembers(DynamicallyAccessedMemberKinds.Properties)] T>(
            Utf8JsonWriter writer,
            T value,
            JsonSerializerOptions options,
            ref WriteStack state,
            string? propertyName = null)
        {

cc @MichalStrehovsky @vitek-karas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants