GetPinnableReference on String.cs (#23428)
authorsimplejackcoder <40817635+simplejackcoder@users.noreply.github.com>
Thu, 28 Mar 2019 15:20:15 +0000 (08:20 -0700)
committerJan Kotas <jkotas@microsoft.com>
Thu, 28 Mar 2019 15:20:15 +0000 (08:20 -0700)
* GetPinnableReference on String.cs

* Add attributes for debugger and performance

src/System.Private.CoreLib/shared/System/String.cs

index 1a1b80c..3ae88bb 100644 (file)
@@ -473,6 +473,13 @@ namespace System
             return true;
         }
 
+        /// <summary>
+        /// Returns a reference to the first element of the String. If the string is null, an access will throw a NullReferenceException.
+        /// </summary>
+        [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
+        [NonVersionable]
+        public ref readonly char GetPinnableReference() => ref _firstChar;
+
         internal ref char GetRawStringData() => ref _firstChar;
 
         // Helper for encodings so they can talk to our buffer directly