What if:
- We drop the
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] attribute from the optionalInterface parameter of the RpcMarshalableOptionalInterfaceAttribute constructor.
- We use a source generator to find uses of the
RpcMarshalableOptionalInterfaceAttribute and emit code that:
- Builds up an
RpcTargetMetadata.InterfaceCollection.
- Adds another attribute to the originally annotated member that points to the generated code.
- At runtime when we find
RpcMarshalableOptionalInterfaceAttribute we look for the source generated attribute and use that instead of reflecting over the OptionalInterface type.
We'll get better performance and more trimmable apps.
Doing this later (after our PolyType milestone release) would be problematic for existing applications because libraries may use the attribute but haven't compiled with the source generator, thus breaking an app that trims until all its libraries recompile against the newer StreamJsonRpc.