浏览代码

C#: Add ByteString.Memory alongside ByteString.Span to allow calling e.g. FileStream.WriteAsync() that requires ReadOnlyMemory<byte>

Erik Mavrinac 5 年之前
父节点
当前提交
7de09eb62a
共有 1 个文件被更改,包括 6 次插入0 次删除
  1. 6 0
      csharp/src/Google.Protobuf/ByteString.cs

+ 6 - 0
csharp/src/Google.Protobuf/ByteString.cs

@@ -116,6 +116,12 @@ namespace Google.Protobuf
         /// No data is copied so this is the most efficient way of accessing.
         /// </summary>
         public ReadOnlySpan<byte> Span => new ReadOnlySpan<byte>(bytes);
+
+        /// <summary>
+        /// Provides read-only access to the data of this <see cref="ByteString"/>.
+        /// No data is copied so this is the most efficient way of accessing.
+        /// </summary>
+        public ReadOnlyMemory<byte> Memory => new ReadOnlyMemory<byte>(bytes);
 #endif
 
         /// <summary>