Converter

WithOutputType

WithOutputType is required whenever the destination format cannot be inferred from the output target. When saving to a typed file like output.json, GPAL can infer JSON. When rendering to a string or saving to a database, the output format must be explicit. WithOutputType(DataFormat.CLASS) combined with SaveTo<T> is the path to automapped class deserialization.

Examples

GPAL Fluent: High-level fluent C# API

//DataFormat.CLASS combined with SaveTo<T> is the converter's most powerful pattern - it automaps the source data to your typed class with zero manual mapping code.

// CSV file to JSON string

string json;

GPAL.Converter

.WithInput(GPAL.FileFor("data.csv"))

.WithFirstLineHasColumnNames(true)

.WithOutputType(DataFormat.JSON)

.SaveTo(ref json);


// Grid to XML file

GPAL.Converter

.WithInput(myGrid)

.WithOutputType(DataFormat.XML)

.SaveTo("output.xml");


// JSON file to typed class

var customer = new Customer();

GPAL.Converter

.WithInput(GPAL.FileFor("customer.json"))

.WithOutputType(DataFormat.CLASS)

.SaveTo<Customer>(ref customer);

💬 Ask GPAL