Apq.Cfg provides intelligent encoding detection and handling for configuration files.
By default, Apq.Cfg automatically detects file encoding:
var cfg = new CfgBuilder()
.AddJson("config.json", level: 0, writeable: false, encoding: Encoding.UTF8)
.Build();
Configure encoding rules for specific files or patterns:
var cfg = new CfgBuilder()
.ConfigureEncodingMapping(config =>
{
// Exact path
config.AddReadMapping("/path/to/config.json", EncodingMappingType.ExactPath, Encoding.UTF8);
// Wildcard pattern
config.AddReadMapping("*.ps1", EncodingMappingType.Wildcard, Encoding.UTF8);
// Regex pattern
config.AddReadMapping(@"logs[/\\].*\.log$", EncodingMappingType.Regex, Encoding.Unicode);
})
.AddJson("config.json", level: 0, writeable: false)
.Build();
| Match Type | Default Priority | Example |
|---|---|---|
| ExactPath | 100 | /path/to/config.json |
| Wildcard | 0 | *.ps1 |
| Regex | 0 | logs[/\\].*\.log$ |
| Built-in PowerShell | -100 | *.ps1, *.psm1 |
| Encoding | Use Case |
|---|---|
| UTF-8 | Default, most common |
| UTF-8 with BOM | Windows PowerShell scripts |
| UTF-16 LE | Windows native |
| GB2312/GBK | Chinese legacy systems |