@@ -27,103 +27,95 @@ Install-Package ObjectSemantics.NET
2727
2828## 🚀 Quick Start
2929
30- ### Example 1: Basic Object Property Mapping
30+ ### Example 1: Mapping Object Properties
3131
3232``` csharp
33- // Create model
34- Student student = new Student
33+ Person person = new Person
3534{
36- StudentName = " George Waynne" ,
37- Balance = 2510
35+ Name = " John Doe"
3836};
3937
40- // Define template
41- var template = new ObjectSemanticsTemplate
38+ // Define template and map it using the object
39+ string result = person .Map (" I am {{ Name }}!" );
40+
41+ Console .WriteLine (result );
42+ ```
43+
44+ ** Output:**
45+ ```
46+ I am John Doe!
47+ ```
48+ ---
49+
50+ ### Example 2: Mapping Using String Extension
51+
52+ ``` csharp
53+ Person person = new Person
4254{
43- FileContents = @" My Name is: {{ StudentName }} and my balance is {{ Balance:N2 }} "
55+ Name = " Jane Doe "
4456};
4557
46- // Map object to template
47- string result = template .Map (student );
58+ // You can also start with the string template
59+ string result = " I am {{ Name }}! " .Map (person );
4860
4961Console .WriteLine (result );
5062```
5163
5264** Output:**
5365```
54- My Name is: George Waynne and my balance is 2,510.00
66+ I am Jane Doe!
5567```
56-
5768---
5869
59- ### Example 2 : Mapping Enumerable Collections
70+ ### Example 3 : Mapping Enumerable Collections (Looping)
6071
6172``` csharp
62- Student student = new Student
73+ Person person = new Person
6374{
64- StudentName = " John Doe" ,
65- Invoices = new List <Invoice >
75+ Name = " John Doe" ,
76+ MyCars = new List <Car >
6677 {
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 ) }
78+ new Car { Make = " BMW " , Year = 2023 },
79+ new Car { Make = " Rolls-Royce " , Year = 2020 }
6980 }
7081};
7182
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- };
83+ string template = @"
84+ {{ Name }}'s Cars
85+ {{ #foreach(MyCars) }}
86+ - {{ Year }} {{ Make }}
87+ {{ #endforeach }}" ;
8588
86- string result = template .Map (student );
89+ string result = person .Map (template );
8790
8891Console .WriteLine (result );
8992```
9093
9194** Output:**
9295```
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>
96+ John Doe's Cars
97+ - 2023 BMW
98+ - 2020 Rolls-Royce
11099```
111-
112100---
113101
114- ### Example 3: String Formatters
115-
116- Use format like ` uppercase ` , ` lowercase ` , ` titlecase ` , ` length ` .
102+ ### Example 4: Number Formatting Support
117103
118104``` csharp
119- FileContents = " Uppercase: {{ StudentName:uppercase }}, Length: {{ StudentName:length }}"
105+ Car car = new Car
106+ {
107+ Price = 50000 m
108+ };
109+
110+ string result = car .Map (" {{ Price:#,##0 }} | {{ Price:N5 }}" );
111+
112+ Console .WriteLine (result );
120113```
121- Outputs :
122114
115+ ** Output:**
123116```
124- Uppercase : ALICE , Length : 5
117+ 50,000 | 50,000.00000
125118```
126-
127119---
128120
129121## 💡 More Examples & Documentation
0 commit comments