PostSharp6.3/API Reference/Post­Sharp.​Patterns.​Formatters Namespace/Unsafe­String Class

UnsafeString Class

A generalized representation of a string that can be either backed by a system String, a char[], or an UnsafeStringBuilder. Conversions between these types happen transparently and are cached.
Inheritance Hierarchy
System.Object
  PostSharp.Patterns.Formatters.UnsafeString

Namespace:  PostSharp.Patterns.Formatters
Assembly:  PostSharp.Patterns.Common (in PostSharp.Patterns.Common.dll) Version: 6.3.11.0 (6.3.11.0)
Syntax
C#
public sealed class UnsafeString

The UnsafeString type exposes the following members.

Constructors
  NameDescription
Public methodUnsafeString(Char[])
Initializes a new UnsafeString backed by an array of Char.
Public methodUnsafeString(String)
Initializes a new UnsafeString backed by a String.
Properties
  NameDescription
Public propertyBuffer
Gets an unmanaged pointer to the string.
Public propertyIsImmutable
Determines whether the current UnsafeString is immutable or, when the value of this property is false, if still bound to a mutable. Call the MakeImmutable() method to make the UnsafeString immutable.
Public propertyLength
Gets the number of characters in the string.
Methods
  NameDescription
Public methodMakeImmutable
If the current UnsafeString is bound to its origin UnsafeStringBuilder, evaluates the UnsafeStringBuilder and breaks the binding, so that later changes in the UnsafeStringBuilder do not cause changes in the current UnsafeString. This method also prevents the UnsafeString form being recycled.
Public methodToCharArray
Gets an ArraySegment<T> representing the current UnsafeString.
Public methodToString
Returns a string that represents the current object.
(Overrides Object.ToString().)
Remarks

Because an UnsafeString can be backed by a UnsafeStringBuilder, which is a mutable type, and is generally pooled and reused for different purposes, it is generally not safe to evaluate an UnsafeString at a different moment than the one designed by the API that exposes the UnsafeString. To make it safe to evaluate the UnsafeString at any moment, call the MakeImmutable() method, which unbounds the UnsafeString from its parent UnsafeStringBuilder.

See Also