Table of Contents

Class ConfigExporter

Namespace
Apq.Cfg.Snapshot
Assembly
Apq.Cfg.dll

配置快照导出器

public static class ConfigExporter
Inheritance
ConfigExporter
Inherited Members

Remarks

提供配置快照导出的核心功能。支持内置格式和自定义导出器。

Methods

Export(ICfgRoot, ExportOptions?)

使用默认 JSON 格式导出配置

public static string Export(ICfgRoot cfg, ExportOptions? options = null)

Parameters

cfg ICfgRoot

配置根

options ExportOptions

导出选项

Returns

string

导出的配置字符串

Export(ICfgRoot, SnapshotExporter, ExportOptions?)

使用自定义导出器导出配置

public static string Export(ICfgRoot cfg, SnapshotExporter exporter, ExportOptions? options = null)

Parameters

cfg ICfgRoot

配置根

exporter SnapshotExporter

导出器委托

options ExportOptions

导出选项

Returns

string

导出的配置字符串

Examples

// 使用内置导出器
var json = ConfigExporter.Export(cfg, SnapshotExporters.Json);
var env = ConfigExporter.Export(cfg, SnapshotExporters.Env);

// 使用自定义导出器
var custom = ConfigExporter.Export(cfg, (data, ctx) => string.Join("\n", data.Select(x => $"{x.Key}={x.Value}")));

ExportAsync(ICfgRoot, SnapshotExporter, Stream, ExportOptions?, CancellationToken)

使用自定义导出器导出配置到流

public static Task ExportAsync(ICfgRoot cfg, SnapshotExporter exporter, Stream stream, ExportOptions? options = null, CancellationToken cancellationToken = default)

Parameters

cfg ICfgRoot
exporter SnapshotExporter
stream Stream
options ExportOptions
cancellationToken CancellationToken

Returns

Task

ExportAsync(ICfgRoot, Stream, ExportOptions?, CancellationToken)

导出配置到流

public static Task ExportAsync(ICfgRoot cfg, Stream stream, ExportOptions? options = null, CancellationToken cancellationToken = default)

Parameters

cfg ICfgRoot
stream Stream
options ExportOptions
cancellationToken CancellationToken

Returns

Task

ExportToDictionary(ICfgRoot, ExportOptions?)

导出配置为字典

public static IReadOnlyDictionary<string, string?> ExportToDictionary(ICfgRoot cfg, ExportOptions? options = null)

Parameters

cfg ICfgRoot

配置根

options ExportOptions

导出选项(仅使用过滤和脱敏选项)

Returns

IReadOnlyDictionary<string, string>

扁平化的配置字典

ExportToFileAsync(ICfgRoot, SnapshotExporter, string, ExportOptions?, CancellationToken)

使用自定义导出器导出配置到文件

public static Task ExportToFileAsync(ICfgRoot cfg, SnapshotExporter exporter, string filePath, ExportOptions? options = null, CancellationToken cancellationToken = default)

Parameters

cfg ICfgRoot
exporter SnapshotExporter
filePath string
options ExportOptions
cancellationToken CancellationToken

Returns

Task

ExportToFileAsync(ICfgRoot, string, ExportOptions?, CancellationToken)

导出配置到文件

public static Task ExportToFileAsync(ICfgRoot cfg, string filePath, ExportOptions? options = null, CancellationToken cancellationToken = default)

Parameters

cfg ICfgRoot
filePath string
options ExportOptions
cancellationToken CancellationToken

Returns

Task