Skip to content
Bryan Watts edited this page Feb 1, 2015 · 5 revisions

Welcome to the wiki home of Totem! There is some cool stuff in here - check out these examples and dig in to find out more.

// Fluent writes

var example = Text
    .Of("Some text")
    .WriteLine()
    .WriteLine("Other text")
    .WriteLine("Formatted: {0} = {1}", "x", 5)
    .WriteInParentheses("Parenthesized");

// Deferred and composable

example = example
    .WriteTwoLines()
    .WriteIf(1 == 1, "True", "False")
    .WriteIf(1 == 2, "True", "False")
    .WriteIf(1 == 2, "True")
    .WriteTwoLines()
    .WriteSeparatedBy(" + ", new[] { 1, 2, 3 })

// Implicit conversion to string

Console.Write(example);

| Some text
| Other text
| Formatted: x = 5
| (Parenthesized)
| 
| True
| False
| 
| 1 + 2 + 3

// Implicit conversion from string/char

Text stringText = "example";
Text charText = 'e';

// Implicit conversion from Action<TextWriter>

Action<TextWriter> action = writer => writer.Write("example");

Text actionText = action;

// Operators

Console.Write("x = " + Text.Of(5));

| x = 5

// One Text operation converts an entire expression to Text

Console.Write(Text.Of("x = ") + 6);

| x = 6

Console.Write(Text.of("x =") + 7 + Text.Line + "y = " + true);

| x = 7
| y = True
Clone this wiki locally