@@ -34,90 +34,100 @@ Install-Package ObjectSemantics.NET
3434
3535## 🚀 Quick Start
3636
37- ### Example 1: Basic Object Property Mapping
37+ ### Example 1: Mapping Object Properties
3838
3939``` csharp
40- // Create model
41- Student student = new Student
40+ Person person = new Person
4241{
43- StudentName = " George Waynne" ,
44- Balance = 2510
42+ Name = " John Doe"
4543};
4644
47- // Define template
48- var template = new ObjectSemanticsTemplate
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
4962{
50- FileContents = @" My Name is: {{ StudentName }} and my balance is {{ Balance:N2 }} "
63+ Name = " Jane Doe "
5164};
5265
53- // Map object to template
54- string result = template .Map (student );
66+ // You can also start with the string template
67+ string result = " I am {{ Name }}! " .Map (person );
5568
5669Console .WriteLine (result );
5770```
5871
5972** Output:**
6073```
61- My Name is: George Waynne and my balance is 2,510.00
74+ I am Jane Doe!
6275```
6376
6477---
6578
66- ### Example 2 : Mapping Enumerable Collections
79+ ### Example 3 : Mapping Enumerable Collections (Looping)
6780
6881``` csharp
69- Student student = new Student
82+ Person person = new Person
7083{
71- StudentName = " John Doe" ,
72- Invoices = new List <Invoice >
84+ Name = " John Doe" ,
85+ MyCars = new List <Car >
7386 {
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 ) }
87+ new Car { Make = " BMW " , Year = 2023 },
88+ new Car { Make = " Rolls-Royce " , Year = 2020 }
7689 }
7790};
7891
79- var template = new ObjectSemanticsTemplate
92+ string template = @"
93+ {{ Name }}'s Cars
94+ {{ #foreach(MyCars) }}
95+ - {{ Year }} {{ Make }}
96+ {{ #endforeach }}" ;
97+
98+ string result = person .Map (template );
99+
100+ Console .WriteLine (result );
101+ ```
102+
103+ ** Output:**
104+ ```
105+ John Doe's Cars
106+ - 2023 BMW
107+ - 2020 Rolls-Royce
108+ ```
109+
110+ ---
111+
112+ ### Example 4: Number Formatting Support
113+
114+ ``` csharp
115+ Car car = new Car
80116{
81- FileContents = @" {{ StudentName }} Invoices
82- {{ #foreach(Invoices) }}
83- <tr>
84- <td>{{ Id }}</td>
85- <td>{{ RefNo }}</td>
86- <td>{{ Narration }}</td>
87- <td>{{ Amount:N0 }}</td>
88- <td>{{ InvoiceDate:yyyy-MM-dd }}</td>
89- </tr>
90- {{ #endforeach }}"
117+ Price = 50000 m
91118};
92119
93- string result = template .Map (student );
120+ string result = car .Map (" {{ Price:#,##0 }} | {{ Price:N5 }} " );
94121
95122Console .WriteLine (result );
96123```
97124
98125** Output:**
99126```
100- John Doe Invoices
101-
102- <tr>
103- <td>2</td>
104- <td>INV_002</td>
105- <td>Grade II Fees Invoice</td>
106- <td>2,000</td>
107- <td>2023-04-01</td>
108- </tr>
109-
110- <tr>
111- <td>1</td>
112- <td>INV_001</td>
113- <td>Grade I Fees Invoice</td>
114- <td>320</td>
115- <td>2022-08-01</td>
116- </tr>
127+ 50,000 | 50,000.00000
117128```
118129
119130---
120-
121131## 🧪 More Samples
122132
123133Explore more usage examples and edge cases in the test project:
0 commit comments