Class EncodingOptions
Specifies options that is related to the Encoding class.
public class EncodingOptions : IEncodingOptions, IParameterObject
- Inheritance
-
EncodingOptions
- Implements
- Derived
Examples
The following example demonstrates how to use
using System;
using System.Text;
using Cuemon.Text; // for EncodingOptions, PreambleSequence
namespace MyApp.Examples;
public class EncodingOptionsExample
{
public void Demonstrate()
{
// Create options with UTF-8 encoding, removing the BOM preamble
var options = new EncodingOptions
{
Encoding = Encoding.UTF8,
Preamble = PreambleSequence.Remove
};
Console.WriteLine(options.Encoding.EncodingName); // Unicode (UTF-8)
Console.WriteLine(options.Preamble); // Remove
// Create options that keep the preamble
var preserveOptions = new EncodingOptions
{
Encoding = Encoding.Unicode,
Preamble = PreambleSequence.Keep
};
Console.WriteLine(preserveOptions.Preamble); // Keep
// Encoding property validates for null
// options.Encoding = null; // throws ArgumentNullException
}
}
Constructors
EncodingOptions()
Initializes a new instance of the EncodingOptions class.
public EncodingOptions()
Remarks
The following table shows the initial property values for an instance of EncodingOptions.
| Property | Initial Value |
|---|---|
| Preamble | DefaultPreambleSequence |
| Encoding | DefaultEncoding |
Properties
DefaultEncoding
Gets or sets the default encoding of EncodingOptions. Default is UTF8.
public static Encoding DefaultEncoding { get; set; }
Property Value
Remarks
Warning: changing this value should be thought through carefully as it can change the behavior you have come to expect. Consider using local adjustment instead.
DefaultPreambleSequence
Gets or sets the default preamble action of EncodingOptions. Default is Remove.
public static PreambleSequence DefaultPreambleSequence { get; set; }
Property Value
- PreambleSequence
The default preamble action to use in Encoding related operations.
Remarks
Warning: changing this value should be thought through carefully as it can change the behavior you have come to expect. Consider using local adjustment instead.
Encoding
Gets or sets the encoding for the operation.
public Encoding Encoding { get; set; }
Property Value
- Encoding
The encoding for the operation.
Exceptions
- ArgumentNullException
valuecannot be null.
Preamble
Gets or sets the action to take in regards to encoding related preamble sequences.
public PreambleSequence Preamble { get; set; }
Property Value
- PreambleSequence
A value that indicates whether to preserve or remove preamble sequences.