EncodingOptions Class
Definition
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
| Name | Description |
|---|---|
| EncodingOptions() | Initializes a new instance of the EncodingOptions class. |
Properties
| Name | Description |
|---|---|
| DefaultEncoding | Gets or sets the default encoding of EncodingOptions. Default is UTF8. |
| DefaultPreambleSequence | Gets or sets the default preamble action of EncodingOptions. Default is Remove. |
| Encoding | Gets or sets the encoding for the operation. |
| Preamble | Gets or sets the action to take in regards to encoding related preamble sequences. |