/// <summary> /// Encodes a reference to a type. /// </summary> /// <param name="type"><see cref="TypeDefinitionHandle"/> or <see cref="TypeReferenceHandle"/>.</param> /// <param name="isValueType">True to mark the type as value type, false to mark it as a reference type in the signature.</param> /// <exception cref="ArgumentException"><paramref name="type"/> doesn't have the expected handle kind.</exception> public void Type(EntityHandle type, bool isValueType) { // Get the coded index before we start writing anything (might throw argument exception): // Note: We don't allow TypeSpec as per https://github.com/dotnet/corefx/blob/master/src/System.Reflection.Metadata/specs/Ecma-335-Issues.md#proposed-specification-change int codedIndex = CodedIndex.ToTypeDefOrRef(type); ClassOrValue(isValueType); Builder.WriteCompressedInteger(codedIndex); }
/// <summary> /// Starts a generic instantiation signature. /// </summary> /// <param name="genericType"><see cref="TypeDefinitionHandle"/> or <see cref="TypeReferenceHandle"/>.</param> /// <param name="genericArgumentCount">Generic argument count.</param> /// <param name="isValueType">True to mark the type as value type, false to mark it as a reference type in the signature.</param> /// <exception cref="ArgumentException"><paramref name="genericType"/> doesn't have the expected handle kind.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="genericArgumentCount"/> is not in range [1, 0xffff].</exception> public GenericTypeArgumentsEncoder GenericInstantiation(EntityHandle genericType, int genericArgumentCount, bool isValueType) { if (unchecked ((uint)(genericArgumentCount - 1)) > ushort.MaxValue - 1) { Throw.ArgumentOutOfRange(nameof(genericArgumentCount)); } // Get the coded index before we start writing anything (might throw argument exception): // Note: We don't allow TypeSpec as per https://github.com/dotnet/corefx/blob/master/src/System.Reflection.Metadata/specs/Ecma-335-Issues.md#proposed-specification-change int codedIndex = CodedIndex.ToTypeDefOrRef(genericType); Builder.WriteByte((byte)SignatureTypeCode.GenericTypeInstance); ClassOrValue(isValueType); Builder.WriteCompressedInteger(codedIndex); Builder.WriteCompressedInteger(genericArgumentCount); return(new GenericTypeArgumentsEncoder(Builder)); }