- Notifications
You must be signed in to change notification settings - Fork 1
Home
George Njeri (Swagfin) edited this page Mar 7, 2026
·
8 revisions
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.
Install-Package ObjectSemantics.NETusingObjectSemantics.NET;publicclassPerson{publicstringName{get;set;}publicintAge{get;set;}}varperson=newPerson{Name="John",Age=30};stringresult=person.Map("Hi {{ Name }}, age {{ Age }}");// Hi John, age 30You can also map from the template side:
stringresult="Hi {{ Name }}".Map(person);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 TECHNOLOGIESPass 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);Use TemplateMapperOptions when rendering XML-safe output:
varmodel=newMessageModel{Name="Tom & Jerry <Ltd>"};stringresult=model.Map("{{ Name }}",null,newTemplateMapperOptions{XmlCharEscaping=true});// Tom & Jerry <Ltd>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);