@@ -13,13 +13,6 @@ This is especially useful when you want to dynamically generate content such as:
1313- Reports or invoices
1414- Config files
1515- Logging output
16-
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-
2316---
2417
2518## 📦 Installation
@@ -34,105 +27,110 @@ Install-Package ObjectSemantics.NET
3427
3528## 🚀 Quick Start
3629
37- ### Example 1: Mapping Object Properties
30+ ### Example 1: Basic Object Property Mapping
3831
3932``` csharp
40- Person person = new Person
33+ // Create model
34+ Student student = new Student
4135{
42- Name = " John Doe"
36+ StudentName = " George Waynne" ,
37+ Balance = 2510
4338};
4439
45- // Define template and map it using the object
46- string result = person .Map (" I am {{ Name }}!" );
47-
48- Console .WriteLine (result );
49- ```
50-
51- ** Output:**
52- ```
53- I am John Doe!
54- ```
55-
56- ---
57-
58- ### Example 2: Mapping Using String Extension
59-
60- ``` csharp
61- Person person = new Person
40+ // Define template
41+ var template = new ObjectSemanticsTemplate
6242{
63- Name = " Jane Doe "
43+ FileContents = @" My Name is: {{ StudentName }} and my balance is {{ Balance:N2 }} "
6444};
6545
66- // You can also start with the string template
67- string result = " I am {{ Name }}! " .Map (person );
46+ // Map object to template
47+ string result = template .Map (student );
6848
6949Console .WriteLine (result );
7050```
7151
7252** Output:**
7353```
74- I am Jane Doe!
54+ My Name is: George Waynne and my balance is 2,510.00
7555```
7656
7757---
7858
79- ### Example 3 : Mapping Enumerable Collections (Looping)
59+ ### Example 2 : Mapping Enumerable Collections
8060
8161``` csharp
82- Person person = new Person
62+ Student student = new Student
8363{
84- Name = " John Doe" ,
85- MyCars = new List <Car >
64+ StudentName = " John Doe" ,
65+ Invoices = new List <Invoice >
8666 {
87- new Car { Make = " BMW " , Year = 2023 },
88- new Car { Make = " Rolls-Royce " , Year = 2020 }
67+ new Invoice { Id = 2 , RefNo = " INV_002 " , Narration = " Grade II Fees " , Amount = 2000 , InvoiceDate = new DateTime ( 2023 , 04 , 01 ) },
68+ new Invoice { Id = 1 , RefNo = " INV_001 " , Narration = " Grade I Fees " , Amount = 320 , InvoiceDate = new DateTime ( 2022 , 08 , 01 ) }
8969 }
9070};
9171
92- string template = @"
93- {{ Name }}'s Cars
94- {{ #foreach(MyCars) }}
95- - {{ Year }} {{ Make }}
96- {{ #endforeach }}" ;
72+ var template = new ObjectSemanticsTemplate
73+ {
74+ FileContents = @" {{ StudentName }} Invoices
75+ {{ #foreach(Invoices) }}
76+ <tr>
77+ <td>{{ Id }}</td>
78+ <td>{{ RefNo }}</td>
79+ <td>{{ Narration }}</td>
80+ <td>{{ Amount:N0 }}</td>
81+ <td>{{ InvoiceDate:yyyy-MM-dd }}</td>
82+ </tr>
83+ {{ #endforeach }}"
84+ };
9785
98- string result = person .Map (template );
86+ string result = template .Map (student );
9987
10088Console .WriteLine (result );
10189```
10290
10391** Output:**
10492```
105- John Doe's Cars
106- - 2023 BMW
107- - 2020 Rolls-Royce
93+ John Doe Invoices
94+
95+ <tr>
96+ <td>2</td>
97+ <td>INV_002</td>
98+ <td>Grade II Fees</td>
99+ <td>2,000</td>
100+ <td>2023-04-01</td>
101+ </tr>
102+
103+ <tr>
104+ <td>1</td>
105+ <td>INV_001</td>
106+ <td>Grade I Fees</td>
107+ <td>320</td>
108+ <td>2022-08-01</td>
109+ </tr>
108110```
109111
110112---
111113
112- ### Example 4: Number Formatting Support
113-
114- ``` csharp
115- Car car = new Car
116- {
117- Price = 50000 m
118- };
114+ ### Example 3: String Formatters
119115
120- string result = car . Map ( " {{ Price:#,##0 }} | {{ Price:N5 }} " );
116+ Use format like ` uppercase ` , ` lowercase ` , ` titlecase ` , ` length ` .
121117
122- Console .WriteLine (result );
118+ ``` csharp
119+ FileContents = " Uppercase: {{ StudentName:uppercase }}, Length: {{ StudentName:length }}"
123120```
121+ Outputs :
124122
125- ** Output:**
126123```
127- 50,000 | 50,000.00000
124+ Uppercase : ALICE , Length : 5
128125```
129126
130127---
131- ## 🧪 More Samples
132128
133- Explore more usage examples and edge cases in the test project:
129+ ## 💡 More Examples & Documentation
130+
131+ Explore more usage examples and edge cases in the Wiki Page:
134132
135- 📁 [ ` ObjectSemantics.NET.Tests ` ] ( ./ ObjectSemantics.NET.Tests )
133+ 📁 [ ` Wiki Page ` ] ( https://github.com/swagfin/ ObjectSemantics.NET/wiki/%F0%9F%9B%A0-Usage-Guide )
136134
137135---
138136
0 commit comments