Object-to-template mapping for .NET with nested property support, loops, conditions, formatting, and lightweight calculations.
Use it when you need fast, readable template mapping for:
- Email and SMS templates
- Receipts, invoices, and reports
- Notification payloads
- Config and log rendering
- Direct property mapping:
{{ Name }} - Nested property mapping:
{{ Customer.BankingDetail.BankName }} - Collection loops:
{{ #foreach(Items) }}...{{ #endforeach }} - Conditional blocks:
{{ #if(Age >= 18) }}...{{ #else }}...{{ #endif }} - Built-in formatting for number/date/string
- XML escaping option (
XmlCharEscaping = true) - Calculation functions:
sum,avg,count,min,maxcalcarithmetic expressions
Install from NuGet:
Install-Package ObjectSemantics.NETusing ObjectSemantics.NET;
var person = new Person { Name = "John Doe" };
string output = person.Map("Hello {{ Name }}");
// Hello John Doevar payment = new CustomerPayment
{
Amount = 100000000,
Customer = new Customer
{
CompanyName = "CRUDSOFT TECHNOLOGIES"
}
};
string result = payment.Map("Paid Amount: {{ Amount:N2 }} By {{ Customer.CompanyName }}");
// Paid Amount: 100,000,000.00 By CRUDSOFT TECHNOLOGIESstring template = "{{ #foreach(Items) }}[{{ Quantity }}x{{ Name }}={{ LineTotal:N2 }}]{{ #endforeach }}";string template = "{{ #if(IsPaid == true) }}PAID{{ #else }}UNPAID{{ #endif }}";// Aggregates
"{{ __sum(Customer.Payments.Amount):N2 }}"
"{{ _avg(Customer.Payments.PaidAmount):N2 }}"
"{{ __count(Customer.Payments.Amount) }}"
// Arithmetic expression
"{{ __calc(PaidAmount - Customer.CreditLimit):N2 }}"Detailed wiki files are available at the Wiki Page:
Contributions are welcome through issues and pull requests.