public static void SetAccessControl(this PipeStream stream, PipeSecurity pipeSecurity)
{
// PipeState can not be Closed and the Handle can not be null or closed
if (pipeSecurity == null)
{
throw new ArgumentNullException(nameof(pipeSecurity));
}
var handle = stream.SafePipeHandle; // A non-null, open handle implies a non-closed PipeState.
// NamedPipeClientStream: PipeState can not be WaitingToConnect or Broken. WaitingToConnect is covered by the SafePipeHandle check.
if (stream is NamedPipeClientStream && !stream.IsConnected) // Pipe could also be WaitingToConnect, Broken, Disconnected, or Closed.
{
throw new InvalidOperationException(SR.InvalidOperation_PipeNotYetConnected);
}
pipeSecurity.Persist(handle);
}
}