Show / Hide Table of Contents

Struct EncodingContext

Represents text encoding context.

Implements
ICloneable
IResettable
Inherited Members
ValueType.Equals(object)
ValueType.GetHashCode()
ValueType.ToString()
object.Equals(object, object)
object.GetType()
object.ReferenceEquals(object, object)
Namespace: DotNext.Text
Assembly: DotNext.IO.dll
Syntax
public readonly struct EncodingContext : ICloneable, IResettable
Remarks

The context represents an encoding cache to avoid memory allocations for each round of string encoding caused by methods of StreamExtensions class. It cannot be shared across parallel flows or threads. However, you can call Copy() method to create an independent copy of this context for separated async flow or thread.

Constructors

| Edit this page View Source

EncodingContext(Encoding, bool)

Represents text encoding context.

Declaration
public EncodingContext(Encoding encoding, bool reuseEncoder)
Parameters
Type Name Description
Encoding encoding

The encoding to be used for converting string into bytes.

bool reuseEncoder

true to reuse the encoder between encoding operations; false to create separated encoder for each encoding operation.

Remarks

The context represents an encoding cache to avoid memory allocations for each round of string encoding caused by methods of StreamExtensions class. It cannot be shared across parallel flows or threads. However, you can call Copy() method to create an independent copy of this context for separated async flow or thread.

Exceptions
Type Condition
ArgumentNullException

encoding is null.

Properties

| Edit this page View Source

Encoding

Gets encoding associated with this context.

Declaration
public Encoding Encoding { get; }
Property Value
Type Description
Encoding
Exceptions
Type Condition
ArgumentNullException

encoding is null.

Methods

| Edit this page View Source

Copy()

Creates independent copy of this context that can be used in separated async flow or thread.

Declaration
public EncodingContext Copy()
Returns
Type Description
EncodingContext

The independent copy of this context.

Exceptions
Type Condition
ArgumentNullException

encoding is null.

| Edit this page View Source

Reset()

Sets the encapsulated encoder to its initial state.

Declaration
public void Reset()
Exceptions
Type Condition
ArgumentNullException

encoding is null.

Operators

| Edit this page View Source

implicit operator EncodingContext(Encoding)

Creates encoding context.

Declaration
public static implicit operator EncodingContext(Encoding encoding)
Parameters
Type Name Description
Encoding encoding

The text encoding.

Returns
Type Description
EncodingContext
Exceptions
Type Condition
ArgumentNullException

encoding is null.

Implements

ICloneable
IResettable

Extension Methods

BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, ReadOnlySpan<T>)
Collection.ToAsyncEnumerator<TEnumerator, T>(TEnumerator, CancellationToken)
Collection.ToClassicEnumerator<TEnumerator, T>(TEnumerator)
Enumerator.Skip<TEnumerator, T>(ref TEnumerator, int)
ExpressionBuilder.Const<T>(T)
  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾