11# ObjectSemantics.NET
22[ ![ FOSSA Status] ( https://app.fossa.com/api/projects/git%2Bgithub.com%2Fswagfin%2FObjectSemantics.NET.svg?type=shield )] ( https://app.fossa.com/projects/git%2Bgithub.com%2Fswagfin%2FObjectSemantics.NET?ref=badge_shield )
33
4- Simple Object to File Mapper that supports string formatting
4+ ** Simple and flexible object-to-template string mapper with formatting support **
55
6- ## Overview
6+ ## 🧠 Overview
77
8- * Maps properties from a source object to a template string and returns the result. This is useful for dynamically generating strings based on object properties .
8+ ** ObjectSemantics.NET ** is a lightweight C# library that lets you inject object property values directly into string templates much like [ Handlebars ] ( https://handlebarsjs.com/ ) or Helm templates, but focused on .NET .
99
10- ## Install
10+ This is especially useful when you want to dynamically generate content such as:
11+ - Email templates
12+ - HTML fragments
13+ - Reports or invoices
14+ - Config files
15+ - Logging output
1116
12- * NuGet Package*
13- ```
17+ It supports:
18+ - ✅ Plain object property injection (` {{ PropertyName }} ` )
19+ - ✅ Additional external parameters
20+ - ✅ Enumerable collections with looping (` #foreach ` )
21+ - ✅ Built-in string, date, and number formatting
22+
23+ ---
24+
25+ ## 📦 Installation
26+
27+ Install from [ NuGet] ( https://www.nuget.org/packages/ObjectSemantics.NET ) :
28+
29+ ``` bash
1430Install-Package ObjectSemantics.NET
1531```
16- https://nuget.org/packages/ObjectSemantics.NET
1732
18- ** USAGE (Example 1)**
19- ``` cs
20- // Create Model
33+ ---
34+
35+ ## 🚀 Quick Start
36+
37+ ### Example 1: Basic Object Property Mapping
38+
39+ ``` csharp
40+ // Create model
2141Student student = new Student
2242{
2343 StudentName = " George Waynne" ,
2444 Balance = 2510
2545};
2646
27- // Define Template
47+ // Define template
2848var template = new ObjectSemanticsTemplate
2949{
3050 FileContents = @" My Name is: {{ StudentName }} and my balance is {{ Balance:N2 }}"
3151};
3252
33- // Map Object to Template
34- string generatedTemplate = template .Map (student );
53+ // Map object to template
54+ string result = template .Map (student );
55+
56+ Console .WriteLine (result );
57+ ```
3558
36- // Output the result
37- Console .WriteLine (generatedTemplate );
59+ ** Output:**
3860```
39- *** Output***
40- ``` console
4161My Name is: George Waynne and my balance is 2,510.00
4262```
4363
44- ** USAGE (Example 2)**
64+ ---
65+
66+ ### Example 2: Mapping Enumerable Collections
4567
4668``` csharp
47- // Create Model
4869Student student = new Student
4970{
5071 StudentName = " John Doe" ,
5172 Invoices = new List <Invoice >
5273 {
53- new Invoice { Id = 2 , RefNo = " INV_002" , Narration = " Grade II Fees Invoice" , Amount = 2000 , InvoiceDate = new DateTime (2023 , 04 , 01 ) },
54- new Invoice { Id = 1 , RefNo = " INV_001" , Narration = " Grade I Fees Invoice" , Amount = 320 , InvoiceDate = new DateTime (2022 , 08 , 01 ) }
74+ new Invoice { Id = 2 , RefNo = " INV_002" , Narration = " Grade II Fees Invoice" , Amount = 2000 , InvoiceDate = new DateTime (2023 , 04 , 01 ) },
75+ new Invoice { Id = 1 , RefNo = " INV_001" , Narration = " Grade I Fees Invoice" , Amount = 320 , InvoiceDate = new DateTime (2022 , 08 , 01 ) }
5576 }
5677};
5778
58- // Define Template
5979var template = new ObjectSemanticsTemplate
6080{
6181 FileContents = @" {{ StudentName }} Invoices
62- {{ #foreach(Invoices) }}
82+ {{ #foreach(Invoices) }}
6383<tr>
6484 <td>{{ Id }}</td>
6585 <td>{{ RefNo }}</td>
@@ -70,14 +90,13 @@ var template = new ObjectSemanticsTemplate
7090{{ #endforeach }}"
7191};
7292
73- // Map Object to Template
74- string generatedTemplate = template .Map (student );
93+ string result = template .Map (student );
94+
95+ Console .WriteLine (result );
96+ ```
7597
76- // Output the result
77- Console .WriteLine (generatedTemplate );
98+ ** Output:**
7899```
79- *** Output***
80- ``` console
81100John Doe Invoices
82101
83102<tr>
@@ -95,11 +114,23 @@ John Doe Invoices
95114 <td>320</td>
96115 <td>2022-08-01</td>
97116</tr>
98-
99117```
100118
101- ## Check out more samples
102- [ ObjectSemantics.NET.Tests] ( https://github.com/swagfin/ObjectSemantics.NET/tree/master/ObjectSemantics.NET.Tests )
119+ ---
120+
121+ ## 🧪 More Samples
122+
123+ Explore more usage examples and edge cases in the test project:
124+
125+ 📁 [ ` ObjectSemantics.NET.Tests ` ] ( ./ObjectSemantics.NET.Tests )
126+
127+ ---
128+
129+ ## 🤝 Contributing
130+
131+ Feel free to open issues or contribute improvements via pull requests!
132+
133+ ---
103134
104- ## License
135+ ## 📄 MIT License
105136[ ![ FOSSA Status] ( https://app.fossa.com/api/projects/git%2Bgithub.com%2Fswagfin%2FObjectSemantics.NET.svg?type=large )] ( https://app.fossa.com/projects/git%2Bgithub.com%2Fswagfin%2FObjectSemantics.NET?ref=badge_large )
0 commit comments