Skip to content

Commit 4b2abcb

Browse files
committed
updated readme
1 parent 0fd188d commit 4b2abcb

1 file changed

Lines changed: 33 additions & 34 deletions

File tree

README.md

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SimpleMapper is a straightforward, easy-to-use object-to-object mapping utility
99
- 🎯 Custom property mapping using attributes
1010
- 🚫 Property exclusion support
1111
- 📝 Support for basic type conversions including enums
12-
- 🔄 Collection mapping support
12+
- 🔄 List mapping with automatic parallelization
1313

1414
## When to Use SimpleMapper
1515

@@ -57,11 +57,9 @@ var dto = new UserDto { Name = "John Doe", Age = 30, Email = "john@example.com"
5757
var entity = SimpleMapper.Map<UserDto, UserEntity>(dto);
5858
```
5959

60-
### Mapping Collections
60+
### Mapping Lists of Objects
6161

62-
SimpleMapper provides support for collections in two ways:
63-
64-
1. Mapping Lists of Objects using `MapList`:
62+
SimpleMapper provides efficient list mapping using `MapList`:
6563

6664
```csharp
6765
var dtoList = new List<UserDto>
@@ -70,52 +68,44 @@ var dtoList = new List<UserDto>
7068
new UserDto { Name = "Jane Doe", Age = 28 }
7169
};
7270

73-
// Maps each object in the list, with automatic parallelization for large lists
71+
// Maps each object in the list
7472
var entityList = SimpleMapper.MapList<UserDto, UserEntity>(dtoList);
7573
```
7674

77-
2. Mapping Collection Properties:
75+
The `MapList` method automatically uses parallelization for lists with more than 100 items, with a maximum degree of parallelism limited to 8 or the number of processor cores, whichever is smaller.
76+
77+
### Custom Property Mapping
78+
79+
Use the `SimpleMapperMappingAttribute` to map properties with different names:
7880

7981
```csharp
80-
public class UserDto
82+
// Destination property specifying the source property name
83+
public class Source
8184
{
82-
public string Name { get; set; }
83-
public List<string> Roles { get; set; }
85+
public string FullName { get; set; }
8486
}
8587

86-
public class UserEntity
88+
public class Destination
8789
{
90+
[SimpleMapperMapping("FullName")]
8891
public string Name { get; set; }
89-
public List<string> Roles { get; set; }
9092
}
9193

92-
// Both Name and Roles will be mapped automatically
93-
var dto = new UserDto
94-
{
95-
Name = "John",
96-
Roles = new List<string> { "Admin", "User" }
97-
};
98-
99-
var entity = SimpleMapper.Map<UserDto, UserEntity>(dto);
100-
```
101-
102-
### Custom Property Mapping
103-
104-
Use the `SimpleMapperMappingAttribute` to map properties with different names:
105-
106-
```csharp
94+
// OR source property specifying the destination property name
10795
public class Source
10896
{
97+
[SimpleMapperMapping("Name")]
10998
public string FullName { get; set; }
11099
}
111100

112101
public class Destination
113102
{
114-
[SimpleMapperMapping("FullName")]
115103
public string Name { get; set; }
116104
}
117105
```
118106

107+
The attribute can be applied to either the source or destination property.
108+
119109
### Ignoring Properties
120110

121111
Use the `SimpleMapperIgnoreAttribute` to exclude properties from mapping:
@@ -150,6 +140,8 @@ SimpleMapper handles various type conversions:
150140
- Nullable type handling
151141
- Custom type conversions through the Convert.ChangeType method
152142

143+
If a conversion fails, SimpleMapper will use the default value for the destination type rather than throwing an exception.
144+
153145
Example of enum conversion:
154146

155147
```csharp
@@ -191,7 +183,11 @@ var dest = SimpleMapper.Map<Source, Destination>(source);
191183

192184
### Cache Management
193185

194-
SimpleMapper maintains a simple cache of mapping functions. If needed, you can manually clear the cache:
186+
SimpleMapper maintains a cache of mapping functions to improve performance:
187+
188+
- Mapping functions are cached for 1 hour after last access
189+
- Old entries are automatically evicted
190+
- The cache can be manually cleared if needed:
195191

196192
```csharp
197193
SimpleMapper.ClearCaches();
@@ -209,9 +205,11 @@ SimpleMapper supports basic type conversions:
209205
- Enum to/from numeric types
210206
- Handling of nullable value types
211207

212-
### Collection Mapping
208+
### Null Value Handling
213209

214-
For collections, SimpleMapper provides a simple `MapList` method that processes items sequentially or in parallel based on collection size.
210+
- Null values are properly handled during mapping
211+
- If the destination property is a non-nullable value type, null source values are skipped
212+
- For nullable destination types, null source values are mapped as null
215213

216214
## Best Practices
217215

@@ -222,11 +220,12 @@ For collections, SimpleMapper provides a simple `MapList` method that processes
222220

223221
## Limitations
224222

225-
- Does not support deep object mapping (nested objects must be mapped separately)
223+
- Does not support deep object mapping (nested complex objects must be mapped separately)
224+
- Does not support mapping collection properties directly (e.g., mapping a List<string> to another List<string>)
226225
- Only public properties are mapped
227226
- Properties must have both getter and setter to be mapped
228-
- Basic caching implementation
229-
- Not optimized for high-performance scenarios
227+
- Basic caching implementation with 1-hour TTL
228+
- Not optimized for extremely high-performance scenarios
230229

231230
## Contributing
232231

0 commit comments

Comments
 (0)