Skip to content

Repository files navigation

ObjectSemantics.NET

FOSSA Status

Object-to-template mapping for .NET with nested property support, loops, conditions, formatting, and lightweight calculations.

Why ObjectSemantics.NET

Use it when you need fast, readable template mapping for:

  • Email and SMS templates
  • Receipts, invoices, and reports
  • Notification payloads
  • Config and log rendering

Features

  • 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, max
    • calc arithmetic expressions

Installation

Install from NuGet:

Install-Package ObjectSemantics.NET

Quick Start

usingObjectSemantics.NET;varperson=newPerson{Name="John Doe"};stringoutput=person.Map("Hello {{ Name }}");// Hello John Doe

Template Examples

Nested mapping

varpayment=newCustomerPayment{Amount=100000000,Customer=newCustomer{CompanyName="CRUDSOFT TECHNOLOGIES"}};stringresult=payment.Map("Paid Amount: {{ Amount:N2 }} By {{ Customer.CompanyName }}");// Paid Amount: 100,000,000.00 By CRUDSOFT TECHNOLOGIES

Loop + format

stringtemplate="{{ #foreach(Items) }}[{{ Quantity }}x{{ Name }}={{ LineTotal:N2 }}]{{ #endforeach }}";

Condition

stringtemplate="{{ #if(IsPaid == true) }}PAID{{ #else }}UNPAID{{ #endif }}";

Calculations

// Aggregates"{{ __sum(Customer.Payments.Amount):N2 }}""{{ _avg(Customer.Payments.PaidAmount):N2 }}""{{ __count(Customer.Payments.Amount) }}"// Arithmetic expression"{{ __calc(PaidAmount - Customer.CreditLimit):N2 }}"

Documentation

Detailed wiki files are available at the Wiki Page:

Contributing

Contributions are welcome through issues and pull requests.

License

MIT

About

Simple Object to File Mapper that supports string formatting

Resources

Stars

6 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages