Cortex Data Framework is a robust, extensible platform designed to facilitate real-time data streaming, processing, and state management. It provides developers with a comprehensive suite of tools and libraries to build scalable, high-performance data pipelines tailored to diverse use cases. By abstracting underlying streaming technologies and state management solutions, Cortex Data Framework enables seamless integration, simplified development workflows, and enhanced maintainability for complex data-driven applications.
$ dotnet add package Cortex.Serialization.YamlCortex.Serialization.Yaml A lightweight, dependency‑free YAML serializer/deserializer for .NET 8+.
Built as part of the Cortex Data Framework, this library provides comprehensive YAML support:
[...] sequences and {...} mappings&anchor and *alias<<: *alias# comments!tag and !!type annotations|) and folded (>) multi-line strings[YamlProperty(Name=…)], [YamlIgnore]IYamlTypeConverter\n, \t, \r, \\, \", and moredotnet add package Cortex.Serialization.Yamlusing Cortex.Serialization.Yaml.Serialization;
using Cortex.Serialization.Yaml.Serialization.Conventions;
public sealed record Address(string Street, string City);
public sealed class Person
{
public string FirstName { get; set; } = string.Empty;
public string LastName { get; set; } = string.Empty;
public int Age { get; set; }
public List<string> Tags { get; set; } = new();
public Address? Address { get; set; }
}
var person = new Person
{
FirstName = "Ada",
LastName = "Lovelace",
Age = 36,
Tags = ["math", "poet"],
Address = new("12 St James's Sq", "London")
};
var serializer = new YamlSerializer(new YamlSerializerSettings
{
NamingConvention = new SnakeCaseConvention(),
EmitNulls = false
});
string yaml = serializer.Serialize(person);
Console.WriteLine(yaml);
var deserializer = new YamlDeserializer(new YamlDeserializerSettings
{
NamingConvention = new SnakeCaseConvention()
});
var model = deserializer.Deserialize<Person>(yaml);
Console.WriteLine($"Hello {model.FirstName} {model.LastName}, {model.Age}");var settings = new YamlSerializerSettings
{
NamingConvention = new CamelCaseConvention(), // how CLR names map to YAML keys
EmitNulls = true, // include null properties
EmitDefaults = true, // include default(T) values
SortProperties = false, // keep reflection order
Indentation = 2, // spaces per indent level
PreferFlowStyle = false, // use [...] and {...} for collections
FlowStyleThreshold = 80, // max line length for flow style
EmitComments = true // emit preserved comments
};var settings = new YamlDeserializerSettings
{
NamingConvention = new SnakeCaseConvention(),
CaseInsensitive = true,
IgnoreUnmatchedProperties = true,
PreserveComments = false, // keep comments for round-trip
ResolveAnchors = true // auto-resolve aliases
};var yaml = """
first_name: Ada
last_name: Lovelace
age: 36
tags:
- math
- poet
address:
street: 12 St James's Sq
city: London
""";
var des = new YamlDeserializer(new YamlDeserializerSettings { NamingConvention = new SnakeCaseConvention() });
var p = des.Deserialize<Person>(yaml);
var s = new YamlSerializer(new YamlSerializerSettings { NamingConvention = new SnakeCaseConvention(), EmitNulls = false });
var outYaml = s.Serialize(p);description: |
First line kept
Second line kept
note: >
Lines are folded
into a single paragraphThese map to string properties on your CLR model.
public sealed class Product
{
[YamlProperty(Name = "product_id")] // explicit YAML key
public Guid Id { get; set; }
[YamlIgnore]
public string? InternalNotes { get; set; }
}public sealed class YesNoBoolConverter : IYamlTypeConverter
{
public bool CanConvert(Type t) => t == typeof(bool);
public object? Read(object? node, Type targetType) => string.Equals(node?.ToString(), "yes", StringComparison.OrdinalIgnoreCase);
public object? Write(object? value, Type declared) => (bool?)value == true ? "yes" : "no";
}
var s = new YamlSerializer(new YamlSerializerSettings());
s.Converters.Add(new YesNoBoolConverter());Parse compact, JSON-like syntax:
tags: [web, api, production]
metadata: {version: 1.0, author: John}var yaml = "tags: [tag1, tag2, tag3]";
var result = YamlDeserializer.Deserialize<MyClass>(yaml);
// Serialize with flow style
var settings = new YamlSerializerSettings { PreferFlowStyle = true };
var output = YamlSerializer.Serialize(obj, settings);Reuse values across your YAML document:
defaults: &defaults
timeout: 30
retries: 3
production:
<<: *defaults
host: prod.example.com
development:
<<: *defaults
host: dev.example.comvar yaml = @"
- &first item1
- second
- *first";
var list = YamlDeserializer.Deserialize<List<string>>(yaml);
// Result: ["item1", "second", "item1"]Automatic quoting for special characters:
var obj = new { Message = "Hello: World", Path = "C:\\Users" };
var yaml = YamlSerializer.Serialize(obj);
// Output: message: "Hello: World"
// path: "C:\\Users"Supported escape sequences: \\, \", \n, \r, \t, \0, \a, \b, \f, \v
For comprehensive documentation, see the User Guide.
We welcome contributions from the community! Whether it's reporting bugs, suggesting features, or submitting pull requests, your involvement helps improve Cortex for everyone.
git checkout -b feature/YourFeaturegit commit -m "Add your feature"git push origin feature/YourFeatureDescribe your changes and submit the pull request for review.
This project is licensed under the MIT License.
Cortex is an open-source project maintained by BuilderSoft. Your support helps us continue developing and improving Cortex. Consider sponsoring us to contribute to the future of resilient streaming platforms.
Contact Us: cortex@buildersoft.io
We'd love to hear from you! Whether you have questions, feedback, or need support, feel free to reach out.

Thank you for using Cortex Data Framework! We hope it empowers you to build scalable and efficient data processing pipelines effortlessly.
Built with ❤️ by the Buildersoft team.