Skip to content
George Njeri (Swagfin) edited this page Mar 7, 2026 · 8 revisions

ObjectSemantics.NET Wiki

Fast, readable object-to-template mapping for .NET applications.

ObjectSemantics.NET helps you build email, SMS, receipt, invoice, and notification templates from your domain objects with minimal code.

Getting Started

1. Install

Install-Package ObjectSemantics.NET

2. Basic Mapping

usingObjectSemantics.NET;publicclassPerson{publicstringName{get;set;}publicintAge{get;set;}}varperson=newPerson{Name="John",Age=30};stringresult=person.Map("Hi {{ Name }}, age {{ Age }}");// Hi John, age 30

You can also map from the template side:

stringresult="Hi {{ Name }}".Map(person);

3. Nested Property Mapping

publicclassCustomer{publicstringCompanyName{get;set;}}publicclassPayment{publicdecimalAmount{get;set;}publicCustomerCustomer{get;set;}}varpayment=newPayment{Amount=100000000m,Customer=newCustomer{CompanyName="CRUDSOFT TECHNOLOGIES"}};stringresult=payment.Map("Paid {{ Amount:N2 }} by {{ Customer.CompanyName }}");// Paid 100,000,000.00 by CRUDSOFT TECHNOLOGIES

4. Additional Parameters

Pass runtime values that are not on your model:

publicclassMessageItem{publicstringName{get;set;}publicintQty{get;set;}}publicclassMessageModel{publicstringName{get;set;}publicboolIsPaid{get;set;}publicList<MessageItem>Items{get;set;}=newList<MessageItem>();}varmodel=newMessageModel{Name="Jane"};varextra=newDictionary<string,object>{["AppName"]="ObjectSemantics.NET",["Meta.Channel"]="EMAIL"};stringresult=model.Map("{{ Name }} via {{ Meta.Channel }} in {{ AppName }}",extra);

5. XML Escaping Option

Use TemplateMapperOptions when rendering XML-safe output:

varmodel=newMessageModel{Name="Tom & Jerry <Ltd>"};stringresult=model.Map("{{ Name }}",null,newTemplateMapperOptions{XmlCharEscaping=true});// Tom &amp; Jerry &lt;Ltd&gt;

6. First Loop and Condition

varmodel=newMessageModel{Name="John",IsPaid=true,Items=newList<MessageItem>{newMessageItem{Name="Keyboard",Qty=1},newMessageItem{Name="Mouse",Qty=2}}};stringtemplate=@"Status: {{ #if(IsPaid == true) }}PAID{{ #else }}UNPAID{{ #endif }}{{ #foreach(Items) }}- {{ Qty }} x {{ Name }}{{ #endforeach }}";stringresult=model.Map(template);

Clone this wiki locally