-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Reflection.Metadata
Milestone
Description
Background and motivation
The roslyn compiler made two changes:
- produce a warning instead of an error for pointer to managed type in unsafe context
- consider
System.TypedReferenceto be managed
As a result, it is possible to emit reference to this type in new contexts. For example in a pointer type.
The natural way to do it in Microsoft.Cci.MetadataWriter.SerializeTypeReference would be to call a SignatureTypeEncoder.TypedReference() method, but that method doesn't exist.
Note that such an API exists on ReturnTypeEncoder, LocalVariableTypeEncoder, and ParameterTypeEncoder already.
Relates to dotnet/roslyn#66328
API Proposal
namespace System.Reflection.Metadata.Ecma335;
public readonly struct SignatureTypeEncoder
{
// additional method:
public void TypedReference()
{
Builder.WriteByte((byte)SignatureTypeCode.TypedReference);
}
}API Usage
private void SerializeTypeReference(SignatureTypeEncoder encoder, ITypeReference typeReference)
{
while (true)
{
if (module.IsPlatformType(typeReference, PlatformType.SystemTypedReference))
{
encoder.TypedReference();
return;
}
... handle other types and recursive scenarios
}Alternative Designs
It is possible to call Builder.WriteByte((byte)SignatureTypeCode.TypedReference); directly. That's the workaround used by the compiler for now.
Risks
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Reflection.Metadata