/// <exception cref="ImageFormatLimitationException">The remaining space on the heap is too small to fit the string.</exception> public UserStringHandle ReserveUserString(int length, out Blob fixup) { int offset = GetNewUserStringHeapOffset(length); int encodedLength = BlobUtilities.GetUserStringByteLength(length); fixup = _userStringWriter.ReserveBytes(BlobWriterImpl.GetCompressedIntegerSize(encodedLength) + encodedLength); new BlobWriter(fixup).WriteBytes(0, fixup.Length); return(MetadataTokens.UserStringHandle(offset)); }
/// <summary> /// Writes string in User String (#US) heap format (see ECMA-335-II 24.2.4 #US and #Blob heaps): /// </summary> /// <remarks> /// The string is UTF16 encoded and prefixed by the its size in bytes. /// /// This final byte holds the value 1 if and only if any UTF16 character within the string has any bit set in its top byte, /// or its low byte is any of the following: 0x01–0x08, 0x0E–0x1F, 0x27, 0x2D, 0x7F. Otherwise, it holds 0. /// The 1 signifies Unicode characters that require handling beyond that normally provided for 8-bit encoding sets. /// </remarks> /// <exception cref="InvalidOperationException">Builder is not writable, it has been linked with another one.</exception> public void WriteUserString(string value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } WriteCompressedInteger(BlobUtilities.GetUserStringByteLength(value.Length)); WriteUTF16(value); WriteByte(BlobUtilities.GetUserStringTrailingByte(value)); }
/// <summary> /// Writes string in User String (#US) heap format (see ECMA-335-II 24.2.4 #US and #Blob heaps): /// </summary> /// <remarks> /// The string is UTF16 encoded and prefixed by the its size in bytes. /// /// This final byte holds the value 1 if and only if any UTF16 character within the string has any bit set in its top byte, /// or its low byte is any of the following: 0x01-0x08, 0x0E-0x1F, 0x27, 0x2D, 0x7F. Otherwise, it holds 0. /// The 1 signifies Unicode characters that require handling beyond that normally provided for 8-bit encoding sets. /// </remarks> /// <exception cref="InvalidOperationException">Builder is not writable, it has been linked with another one.</exception> public void WriteUserString(string value) { if (value is null) { Throw.ArgumentNull(nameof(value)); } WriteCompressedInteger(BlobUtilities.GetUserStringByteLength(value.Length)); WriteUTF16(value); WriteByte(BlobUtilities.GetUserStringTrailingByte(value)); }
/// <summary> /// Reserves space on the User String heap for a string of specified length. /// </summary> /// <param name="length">The number of characters to reserve.</param> /// <param name="reservedUserString"> /// <see cref="Blob"/> representing the entire User String blob (including its length and terminal character). /// Use <see cref="BlobWriter.WriteUserString(string)"/> to fill in the content. /// </param> /// <returns> /// Handle to the reserved User String. /// May be used in <see cref="InstructionEncoder.LoadString(UserStringHandle)"/>. /// </returns> /// <exception cref="ImageFormatLimitationException">The remaining space on the heap is too small to fit the string.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="length"/> is negative.</exception> public UserStringHandle ReserveUserString(int length, out Blob reservedUserString) { if (length < 0) { Throw.ArgumentOutOfRange(nameof(length)); } var handle = GetNewUserStringHandle(); int encodedLength = BlobUtilities.GetUserStringByteLength(length); reservedUserString = _userStringBuilder.ReserveBytes(BlobWriterImpl.GetCompressedIntegerSize(encodedLength) + encodedLength); return(handle); }