IIniSectionFactory<TSection> Interface
Definition
Provides reflection-free conversion between a section type and its INI key/value representation, consumed by the IniSerializer section overloads.
public interface IIniSectionFactory<TSection>
Type Parameters
TSectionThe section type.
- Extension Methods
Remarks
Implementations are typically emitted at compile time by the Bodu.Text.Formats.Generators source generator
for types annotated with IniSectionAttribute, but the interface can equally be implemented by hand
when full control over the key mapping is required. Because no member of this contract inspects types at runtime,
the factory-based serializer paths are safe for trimming and ahead-of-time compilation.
Properties
Keys
Gets the key names of the section type, in declaration order.
IReadOnlyList<string> Keys { get; }
Property Value
- IReadOnlyList<string>
The resolved key names.
Methods
Create(IEnumerable<KeyValuePair<string, string>>)
Creates a section instance from decoded INI entries.
TSection Create(IEnumerable<KeyValuePair<string, string>> entries)
Parameters
entriesIEnumerable<KeyValuePair<string, string>>The section's key/value entries, in source order.
Returns
- TSection
The created section.
Remarks
A conversion error the factory throws, a FormatException, OverflowException, ArgumentException or InvalidCastException, reaches the caller of IniSerializer as an IniSerializationException whose inner exception it is, as the reflection binder reports a value it cannot convert.
GetEntries(TSection)
Converts a section instance to its INI entries, in Keys order.
IEnumerable<KeyValuePair<string, string>> GetEntries(TSection section)
Parameters
sectionTSectionThe section instance.
Returns
- IEnumerable<KeyValuePair<string, string>>
The key/value entries.
Remarks
The entries may leave keys out: a generated factory leaves out the members its ignore conditions omit. The serializer writes exactly the entries it is given.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |