Class HumlConverter<T>
- Namespace
- Huml.Net.Serialization
- Assembly
- Huml.Net.dll
Typed HUML converter for T. Override Read(HumlNode) and
Write(HumlWriterContext, T) to control how T is deserialised and serialised.
public abstract class HumlConverter<T> : HumlConverter
Type Parameters
TThe CLR type this converter handles.
- Inheritance
-
HumlConverter<T>
- Inherited Members
Remarks
Instances are cached and shared across threads — converters must be stateless.
Do not call AppendSerializedValue(object?) with a value of
type T inside Write(HumlWriterContext, T); this creates infinite recursion.
Use AppendRaw(string) for custom HUML output instead.
Methods
CanConvert(Type)
Returns true when this converter can handle typeToConvert.
public override bool CanConvert(Type typeToConvert)
Parameters
typeToConvertTypeThe CLR type to evaluate.
Returns
Read(HumlNode)
Reads a HumlNode and returns the deserialised T value.
public abstract T? Read(HumlNode node)
Parameters
nodeHumlNodeThe fully-parsed AST node for the value being deserialised.
Returns
- T
The deserialised value, or
nullfor nullable types.
Write(HumlWriterContext, T)
Writes value to the serialiser output via context.
public abstract void Write(HumlWriterContext context, T value)
Parameters
contextHumlWriterContextThe serialiser context providing append methods.
valueTThe value to serialise. Never
nullfor reference types — null values are emitted asnullby WriteObject(HumlWriterContext, object) beforeWriteis called.
Remarks
When invoked from a property-level converter context, the output produced by this method
is inserted inline as the scalar value for the mapping entry (key: <output>).
The output must be a single-line HUML scalar (a quoted string, a number, a keyword such
as true / false / null, etc.) — embedded newlines will break the
current mapping entry's syntax. Use AppendRaw(string) only
when you are certain the output is a valid single-line value.