• Stars
    star
    26
  • Rank 930,752 (Top 19 %)
  • Language
    C#
  • License
    Apache License 2.0
  • Created almost 4 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple C# source generator for text templates

Transplator

This project is currently an experiment into the idea of generating C# source code from a text template. The code generation is integrated into the C# compiler using the source generator feature made available starting with the version supporting C# 9.

The input to Transplator is a simple text template file, where literal text is interspersed with C# source code. The output is C# code that, when executed as part of the compiled product, will produce text with literal parts copied over as they are and the C# code in the template contributing dynamic text.

Using the source generator feature has the benefit that the template is turned into strong- and statically-typed C# source code. Any type errors will be caught at compile-time. At run-time, the template output will be produced at native speed, without any interpretation.

The text templates can be used, for example, to generate e-mail messages with certain parts replaced dynamically at run-time.

Format

Anything between {% and %} is considered C# code and everthing else is treated as literal text. For example:

The current date and time is {% DateTime.Now %}.

Transplator has some smarts to distinguish between control flow blocks or statement and expressions that contribute dynamic text, so syntactically, you only need to remember to use {% and %} as delimiters:

{%
    for (var i = 0; i < 10; i++) {
%}
        i = {% i + 1 %}
{%
    }
%}

Like the Liquid templating language, you can use - to trim whitespace from the left or right side:

{%- "left whitespace is trimmed" %}
{% "right whitespace is trimmed" -%}
{%- "left and right whitespace is trimmed" -%}

Like the Scriban templating language, you can use ~ to for non-greedy whitespace trimming:

  • Using a {{~ will remove any whitespace before but will stop on the first newline without including it
  • Using a ~}} will remove any whitespace after including the first newline but will stop after

More Repositories

1

NCrontab

Crontab for .NET
C#
823
star
2

LinqPadless

LINQPad Queries without LINQPad
C#
268
star
3

Fizzler

.NET CSS Selector Engine
C#
120
star
4

High5

HTML parsing & serialization toolset for .NET Standard
HTML
100
star
5

t5

T5 is T4 (Text Template Transformation Toolkit) for .NET Core
C#
75
star
6

JSONPath

JSONPath (XPath-like syntax for JSON) C# implementation
C#
71
star
7

Hazz

CSS Selectors (via Fizzler) for HtmlAgilityPack (HAP)
C#
57
star
8

StackTraceParser

C# parser for .NET & Mono stack traces
C#
54
star
9

CSharpMinifier

.NET Standard Library & Tool for C# source code minification
C#
33
star
10

WebLinq

LINQ to Web or teaching LINQ to do Web so the Web appears like simple LINQ queries
C#
24
star
11

Optuple

.NET Standard Library for giving (bool, T) Option-like semantics
C#
24
star
12

StackTraceFormatter

C# formatter for .NET & Mono stack traces
C#
23
star
13

Jayrock

JSON & JSON-RPC for .NET Framework & Mono
C#
22
star
14

FakeLinqPad

Fake replacement for LINQPad API
C#
16
star
15

Dsv

.NET Standard Library for Parsing DSV (Delimiter-Separated Values) data like CSV
C#
14
star
16

LINQBridge

Re-implementation of LINQ to Objects for .NET Framework 2.0
C#
13
star
17

Escape

JavaScript parser for .NET Standard based on the Esprima code base
JavaScript
12
star
18

TryParsers

TryParse methods done right for .NET Standard
C#
10
star
19

Jacob

A succinct and compositional .NET API for reading JSON
C#
8
star
20

Gini

INI File Format Parser
C#
7
star
21

CSharpMinifierDemo

Single-Page Application based on Blazor (WebAssembly) demonstrating CSharpMinifier in action
CSS
6
star
22

CSharpSyntaxValidator

.NET Core tool to validate C# source syntax
C#
6
star
23

AngryArrays

Extension methods for transforming arrays
C#
6
star
24

Nunycode

Punycode for .NET derived from https://mths.be/punycode
C#
6
star
25

SplitCsvApp

CSV Splitter Utility
C#
5
star
26

NDate

Date (without Time) for .NET
C#
4
star
27

A1

Column-Row with A1-style parsing & formatting
C#
4
star
28

Spawnr

System.Diagnostics.Process.Start Made Simple
C#
3
star
29

Boxing

.NET Standard library for boxing any value
C#
3
star
30

windu

Disk usage database utility written in C#; that is ⚠ not actively maintained!
C#
3
star
31

LinqPadCsvFix

Fix CSV Output of LINQPad Reactive Queries
C#
3
star
32

Crockbase32

C# implementation of Douglas Crockford's Base 32
C#
3
star
33

Rejex

Regex à la LINQ 🚧
C#
3
star
34

XlTableFormat

XlTable format reader
C#
3
star
35

KeyValuePairs

.NET Standard library with helper and extension methods that exclusively deal with KeyValuePair<,>
C#
3
star
36

Gratt

A Generic Vaughn Pratt's top-down operator precedence parser for .NET Standard
C#
3
star
37

dyndlg

Dynamic Dialog Boxes for Windows
C
2
star
38

Interlocker

Interlocked.CompareExchange boilerplate
C#
2
star
39

TextDataReader

An IDataReader implementation for text sources
C#
2
star
40

findpath

Console tool to find a file on the standard Windows search path
C++
2
star
41

Worms

Awaitable Synchronization Primitives Library for .NET
C#
2
star
42

BasicTextFieldParser

Visual Basic's TextFieldParser for .NET Standard
C#
1
star
43

wshgrep

Grep-like using Windows Script Host
JavaScript
1
star
44

VisualFizzler

WinForms Application for visualising CSS Selectors
C#
1
star
45

elvee

Small cross-platform shim in C to run the latest version of an executable
C
1
star
46

cmdqp.cmd

Windows Command Queue Processor Scripts
Batchfile
1
star
47

Delegating.AspNet

.NET Library providing delegated implementations of common ASP.NET interfaces
C#
1
star
48

Builders

This project is work in progress 🚧
C#
1
star
49

Gist

My Gists
JavaScript
1
star
50

Kons

Simple Cons List for .NET
C#
1
star
51

Jayrock.Json

.NET Standard Library for reading and writing JSON
C#
1
star
52

secrets.ps

PowerShell scripts to protect secrets in files via Windows DPAPI (Data Protection API)
PowerShell
1
star
53

recolor

.NET Core Tool that colors regex matches on STDIN lines
C#
1
star
54

JsonChecker

http://www.raboof.com/projects/jsonchecker/
C#
1
star
55

OpenWebClient

An “open” subclass of System.Net.WebClient
C#
1
star
56

pie.ps

Pie = Python installer extraordinaire! A PowerShell script for isolated installation of a project's required versions of Python, pip & packages
PowerShell
1
star
57

WebLinqExamples

Examples of scrapes using WebLINQ
1
star
58

sstart.vbs

WSH script to launch a program without any visible user interface
Visual Basic
1
star
59

Jazmin

.NET Global Tool to filter comments & unnecessary whitespace from JavaScript
C#
1
star
60

NotWebMatrix.Data

Open source clone of mostly WebMatrix.Data and then some more
C#
1
star
61

Choices

Choice types (general discriminated unions) for .NET Standard 1.0+
C#
1
star
62

JmesPath

1
star
63

xls2csv

Utility to format an Excel (BIFF5/BIFF8) worksheet as CSV
JavaScript
1
star
64

Rdatasets.cs

Collection of over a thousand R datasets packaged as a .NET Standard library
C#
1
star
65

Eggado

ADO.NET modernizer
C#
1
star