diff --git a/src/libraries/System.Reflection.Metadata/ref/System.Reflection.Metadata.cs b/src/libraries/System.Reflection.Metadata/ref/System.Reflection.Metadata.cs
index ee3400d6c3f79..61314bfb7fd06 100644
--- a/src/libraries/System.Reflection.Metadata/ref/System.Reflection.Metadata.cs
+++ b/src/libraries/System.Reflection.Metadata/ref/System.Reflection.Metadata.cs
@@ -3064,6 +3064,7 @@ public void Single() { }
public void String() { }
public System.Reflection.Metadata.Ecma335.SignatureTypeEncoder SZArray() { throw null; }
public void Type(System.Reflection.Metadata.EntityHandle type, bool isValueType) { }
+ public void TypedReference() { }
public void UInt16() { }
public void UInt32() { }
public void UInt64() { }
diff --git a/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/Encoding/BlobEncoders.cs b/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/Encoding/BlobEncoders.cs
index 3b7041a9b373c..3ed78ab777a1b 100644
--- a/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/Encoding/BlobEncoders.cs
+++ b/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/Encoding/BlobEncoders.cs
@@ -885,10 +885,20 @@ public void Enum(string enumTypeName)
}
}
+ ///
+ /// Encodes a type in a signature.
+ ///
public readonly struct SignatureTypeEncoder
{
+ ///
+ /// The where the signature is written to.
+ ///
public BlobBuilder Builder { get; }
+ ///
+ /// Creates a .
+ ///
+ /// The where the signature will be written.
public SignatureTypeEncoder(BlobBuilder builder)
{
Builder = builder;
@@ -904,27 +914,79 @@ private void ClassOrValue(bool isValueType)
Builder.WriteByte(isValueType ? (byte)SignatureTypeKind.ValueType : (byte)SignatureTypeKind.Class);
}
+ ///
+ /// Encodes .
+ ///
public void Boolean() => WriteTypeCode(SignatureTypeCode.Boolean);
+ ///
+ /// Encodes .
+ ///
public void Char() => WriteTypeCode(SignatureTypeCode.Char);
+ ///
+ /// Encodes .
+ ///
public void SByte() => WriteTypeCode(SignatureTypeCode.SByte);
+ ///
+ /// Encodes .
+ ///
public void Byte() => WriteTypeCode(SignatureTypeCode.Byte);
+ ///
+ /// Encodes .
+ ///
public void Int16() => WriteTypeCode(SignatureTypeCode.Int16);
+ ///
+ /// Encodes .
+ ///
public void UInt16() => WriteTypeCode(SignatureTypeCode.UInt16);
+ ///
+ /// Encodes .
+ ///
public void Int32() => WriteTypeCode(SignatureTypeCode.Int32);
+ ///
+ /// Encodes .
+ ///
public void UInt32() => WriteTypeCode(SignatureTypeCode.UInt32);
+ ///
+ /// Encodes .
+ ///
public void Int64() => WriteTypeCode(SignatureTypeCode.Int64);
+ ///
+ /// Encodes .
+ ///
public void UInt64() => WriteTypeCode(SignatureTypeCode.UInt64);
+ ///
+ /// Encodes .
+ ///
public void Single() => WriteTypeCode(SignatureTypeCode.Single);
+ ///
+ /// Encodes .
+ ///
public void Double() => WriteTypeCode(SignatureTypeCode.Double);
+ ///
+ /// Encodes .
+ ///
public void String() => WriteTypeCode(SignatureTypeCode.String);
+ ///
+ /// Encodes .
+ ///
+ public void TypedReference() => WriteTypeCode(SignatureTypeCode.TypedReference);
+ ///
+ /// Encodes .
+ ///
public void IntPtr() => WriteTypeCode(SignatureTypeCode.IntPtr);
+ ///
+ /// Encodes .
+ ///
public void UIntPtr() => WriteTypeCode(SignatureTypeCode.UIntPtr);
+ ///
+ /// Encodes .
+ ///
public void Object() => WriteTypeCode(SignatureTypeCode.Object);
///
- /// Writes primitive type code.
+ /// Encodes a primitive type.
///
- /// Any primitive type code except for and .
+ /// Any primitive type code except for .
/// is not valid in this context.
public void PrimitiveType(PrimitiveTypeCode type)
{
@@ -942,6 +1004,7 @@ public void PrimitiveType(PrimitiveTypeCode type)
case PrimitiveTypeCode.UInt64:
case PrimitiveTypeCode.Single:
case PrimitiveTypeCode.Double:
+ case PrimitiveTypeCode.TypedReference:
case PrimitiveTypeCode.IntPtr:
case PrimitiveTypeCode.UIntPtr:
case PrimitiveTypeCode.String:
@@ -949,7 +1012,6 @@ public void PrimitiveType(PrimitiveTypeCode type)
Builder.WriteByte((byte)type);
return;
- case PrimitiveTypeCode.TypedReference:
case PrimitiveTypeCode.Void:
default:
Throw.ArgumentOutOfRange(nameof(type));
@@ -958,7 +1020,7 @@ public void PrimitiveType(PrimitiveTypeCode type)
}
///
- /// Encodes an array type.
+ /// Starts encoding an array type.
/// Returns a pair of encoders that must be used in the order they appear in the parameter list.
///
/// Use first, to encode the type of the element.
@@ -1011,7 +1073,7 @@ public void Type(EntityHandle type, bool isValueType)
}
///
- /// Starts a function pointer signature.
+ /// Starts encoding a function pointer signature.
///
/// Calling convention.
/// Function pointer attributes.
@@ -1051,7 +1113,7 @@ public MethodSignatureEncoder FunctionPointer(
}
///
- /// Starts a generic instantiation signature.
+ /// Starts encoding a generic instantiation signature.
///
/// or .
/// Generic argument count.
@@ -1109,7 +1171,7 @@ public void GenericTypeParameter(int parameterIndex)
}
///
- /// Starts pointer signature.
+ /// Starts encoding a pointer signature.
///
public SignatureTypeEncoder Pointer()
{
@@ -1127,7 +1189,7 @@ public void VoidPointer()
}
///
- /// Starts SZ array (vector) signature.
+ /// Starts encoding an SZ array (vector) signature.
///
public SignatureTypeEncoder SZArray()
{
@@ -1136,7 +1198,7 @@ public SignatureTypeEncoder SZArray()
}
///
- /// Starts a signature of a type with custom modifiers.
+ /// Starts encoding a signature of a type with custom modifiers.
///
public CustomModifiersEncoder CustomModifiers()
{
diff --git a/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/Encoding/BlobEncodersTests.cs b/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/Encoding/BlobEncodersTests.cs
index 0377a9320824e..6af6c5d90e747 100644
--- a/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/Encoding/BlobEncodersTests.cs
+++ b/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/Encoding/BlobEncodersTests.cs
@@ -972,6 +972,10 @@ public void SignatureTypeEncoder_Primitives()
AssertEx.Equal(new byte[] { 0x0E }, b.ToArray());
b.Clear();
+ e.TypedReference();
+ AssertEx.Equal(new byte[] { 0x16 }, b.ToArray());
+ b.Clear();
+
e.IntPtr();
AssertEx.Equal(new byte[] { 0x18 }, b.ToArray());
b.Clear();
@@ -1044,6 +1048,10 @@ public void SignatureTypeEncoder_PrimitiveType()
AssertEx.Equal(new byte[] { 0x0E }, b.ToArray());
b.Clear();
+ e.PrimitiveType(PrimitiveTypeCode.TypedReference);
+ AssertEx.Equal(new byte[] { 0x16 }, b.ToArray());
+ b.Clear();
+
e.PrimitiveType(PrimitiveTypeCode.IntPtr);
AssertEx.Equal(new byte[] { 0x18 }, b.ToArray());
b.Clear();
@@ -1057,7 +1065,6 @@ public void SignatureTypeEncoder_PrimitiveType()
b.Clear();
Assert.Throws(() => e.PrimitiveType(PrimitiveTypeCode.Void));
- Assert.Throws(() => e.PrimitiveType(PrimitiveTypeCode.TypedReference));
Assert.Throws(() => e.PrimitiveType((PrimitiveTypeCode)255));
}