๐Ÿ”ก
Syllabore
GitHub
  • Overview
  • Starting Out
  • Fine-Tuning Generators
    • Positioning
    • Clusters
    • Weights
    • Chancing
    • Transforms
    • Filtering
  • More Techniques
    • Formatters
    • Generator Pools
    • Syllable Sets
    • Generator Serialization
  • More Examples
    • Soft/Hard-Sounding Names
    • Fantasy Names
    • Spaceship Names
    • Futuristic City Names
  • Class Docs
    • FilterCondition
    • FilterConstraint
    • GeneratorPool<T>
    • INameFilter
    • INameTransformer
    • IPotentialAction
    • IRandomizable
    • ISyllableGenerator
    • Name
    • NameFilter
    • NameFormat
    • NameFormatter
    • NameFormatterGeneratorOptions
    • NameGenerator
    • NameGeneratorSerializer
    • NameGeneratorTypeInformation
    • SerializedNameGenerator
    • SyllableGenerator
    • SyllableGeneratorFluentWrapper
    • SyllablePosition
    • SyllableSet
    • Symbol
    • SymbolGenerator
    • SymbolPosition
    • Transform
    • TransformSet
    • TransformStep
    • TransformStepType
Powered by GitBook
On this page
  1. More Techniques

Generator Serialization

PreviousSyllable SetsNextMore Examples

Last updated 1 month ago

When serializing a to a json file, use the convenience class . The convenience class is found in the Syllabore.Json namespace.

Consider the following name generator:

var names = new NameGenerator()
    .Any(x => x
        .First(x => x.Add("bรงฦข").Cluster("dr"))
        .Middle(x => x.Add("aieou").Cluster("ey"))
        .Last(x => x.Add("ใƒ…๐Ÿ‚…๐Ÿ™‚").Cluster("mn")))
    .Filter("zzzy", "abcd")
    .Transform(new TransformSet()
        .Chance(0.5)
        .RandomlySelect(2)
        .Add(x => x.Append("tar"))
        .Add(x => x.Insert(0, "arc"))
        .Add(x => x.Replace(0, "neo")))
    .SetSize(3);

To save this to a file, create a serializer:

var serializer = new NameGeneratorSerializer();
serializer.Serialize(names, "names.json");

To load a name generator from a json file:

var serializer = new NameGeneratorSerializer();
var names = serializer.Deserialize("names.json");

NameGenerator has properties with interfaces as their types. Vanilla .NET deserialization won't work without some advanced setup. This convenience class does the setup for you.

NameGenerator
NameGeneratorSerializer