Explorar o código

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

Erik Mavrinac %!s(int64=5) %!d(string=hai) anos
pai
achega
7de09eb62a
Modificáronse 1 ficheiros con 6 adicións e 0 borrados
  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.
         /// No data is copied so this is the most efficient way of accessing.
         /// </summary>
         /// </summary>
         public ReadOnlySpan<byte> Span => new ReadOnlySpan<byte>(bytes);
         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
 #endif
 
 
         /// <summary>
         /// <summary>