Skip to content

Support marking a string as a Type, but don't require members to be accessed on it #1878

@eerhardt

Description

@eerhardt

In System.ComponentModel.TypeConverter, there are a few instances where it will call Type.GetType(string), and then use the Type to pass into other methods.

An example is the ProvidePropertyAttribute - https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.providepropertyattribute

This attribute can take a string receiverTypeName parameter in its constructor. In order to support this, we need to mark that parameter as DynamicallyAccessedMembers so the linker will see that the Type is being used and not trim the Type. However, in order to use DynamicallyAccessedMembers, we need to specify a DynamicallyAccessedMemberTypes enum. Putting DynamicallyAccessedMemberTypes.None should mark the Type as being preserved, but not mark any of its members.

This also applies to the EditorAttribute's string? baseTypeName parameter. The code calls Type.GetType using this string, but doesn't reflect on anything else on the Type. The Type needs to be preserved, but not necessarily any of its members.

For now I've been using DynamicallyAccessedMemberTypes.PublicParameterlessConstructor to preserve these Types.

cc @vitek-karas @MichalStrehovsky @marek-safar

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions