Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/readme #18

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Automapify/Automapify.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@
<PackageTags>.net 6.0, mapping</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<ItemGroup>
<None Include="docs\readme.md" Pack="true" PackagePath="\"/>
</ItemGroup>
</Project>
145 changes: 145 additions & 0 deletions Automapify/docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Automapify
This dotnet library facilitates object mappings without the need for service setup or configuration.

### Basic Usage
There are two methods for utilizing this tool: Attributes and Configuration
#### **Attributes**

- Specify the property name from the source in the destination object using the `MapProperty` attribute

```csharp
public int Id { get; set; }

public string Name { get; set; }

public int Age { get; set; }

[MapProperty("DateOfBirth")]
public DateTime DOB { get; set; }

public bool IsDeleted { get; set; }

public Classroom Room {get; set; }
```

##### Map to a new object
```csharp
var studentDto = student1.Map<Student,StudentDto>();
```

##### Map to an existing object

```csharp
studentDto.Map<Student,StudentDto>(student1);
```

#### **Configuration**

- Establish a configuration to illustrate the mapping of values.

```csharp
public static class MappingService
{
public static MapifyConfiguration<Student,StudentDtos> StudentConfig()
{
return new MapifyConfigurationBuilder<Student, StudentDto>()
.Map(d => d.Name, s => $"{s.FirstName} {s.LastName}")
.Map(d => d.Age, s => s.DateOfBirth.ToAge())
.Map(d=>d.DOB, s => s.DateOfBirth)
.Map(d=>d.IsDeleted, s => false)
.Map(d=>d.Classroom, s=> s.Room)
.CreateConfig();
}
}
```

##### Map to a new object

```csharp
var studentDto = student.Map<Student,StudentDto>(MappingService.StudentConfig());
```

##### Map to an existing object

```csharp
studentDto.Map<Student,StudentDto>(student1,MappingService.StudentConfig());
```

#### Many to one/many mapping
Automapify now supports many to many and many to one object mapping. You can utilize that by either using the conifguration or attributes.

##### Using `MapProperty` attribute

- Specify the property name from the source in the destination object using the `MapProperty` attribute

```csharp
public int Id { get; set; }

public string Name { get; set; }

public int Age { get; set; }

[MapProperty("DateOfBirth")]
public DateTime DOB { get; set; }

public bool IsDeleted { get; set; }

public Classroom Room {get; set; }
```

###### Map from objects to objects (Many-to-many mapping)
- Map to a new object
```csharp
var studentDtos = student.Map<List<Student>, List<StudentDto>>();
```
- Map to an existing object
```csharp
studentDtos.Map(students);
```
###### Map from object to objects (One-to-many mapping)
- Map to a new object
```csharp
var studentDtos = student.Map<Student, List<StudentDto>>();
```
- Map to an existing object
```csharp
studentDtos.Map(student);
```

##### Using Configuration
- Establish a configuration to illustrate the mapping of values.

```csharp
public static class MappingService
{
public static MapifyConfiguration<Student,StudentDtos> StudentConfig()
{
return new MapifyConfigurationBuilder<Student, StudentDto>()
.Map(d => d.Name, s => $"{s.FirstName} {s.LastName}")
.Map(d => d.Age, s => s.DateOfBirth.ToAge())
.Map(d=>d.DOB, s => s.DateOfBirth)
.Map(d=>d.IsDeleted, s => false)
.Map(d=>d.Classroom, s=> s.Room)
.CreateConfig();
}
}
```

###### Map from objects to objects (Many-to-many mapping)
- Map to a new object
```csharp
var studentDtos = student.Map<List<Student>, List<StudentDto>>(MappingService.StudentConfig());
```
- Map to an existing object
```csharp
studentDtos.Map(students,MappingService.StudentConfig());
```
###### Map from object to objects (One-to-many mapping)
- Map to a new object
```csharp
var studentDtos = student.Map<Student, List<StudentDto>>(MappingService.StudentConfig());
```
- Map to an existing object
```csharp
studentDtos.Map(student,MappingService.StudentConfig());
```
Loading