Skip to content

Commit

Permalink
chore: upgrade docusaurus to v3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
latonz committed Nov 20, 2023
1 parent 1584799 commit 1ca20b1
Show file tree
Hide file tree
Showing 11 changed files with 4,025 additions and 3,306 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ indent_size = 2

# markdown
[*.{md,mdx}]
indent_size = unset
indent_size = 2
trim_trailing_whitespace = false

# Verify settings
Expand Down
90 changes: 44 additions & 46 deletions docs/docs/configuration/derived-type-mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,53 +12,51 @@ Mapperly supports interfaces and base types as mapping sources and targets,
but Mapperly needs to know which derived types exist.
This can be configured with the `MapDerivedTypeAttribute`:

<!-- do not indent this, it won't work, https://stackoverflow.com/a/67579641/3302887 -->

<Tabs>
<TabItem value="declaration" label="Declaration" default>

```csharp
[Mapper]
public static partial class ModelMapper
{
// highlight-start
[MapDerivedType<Banana, BananaDto>] // for c# language level ≥ 11
[MapDerivedType(typeof(Apple), typeof(AppleDto))] // for c# language level < 11
// highlight-end
public static partial FruitDto MapFruit(Fruit source);
}

abstract class Fruit {}
class Banana : Fruit {}
class Apple : Fruit {}

abstract class FruitDto {}
class BananaDto : FruitDto {}
class AppleDto : FruitDto {}
```

</TabItem>
<TabItem value="generated" label="Generated code" default>

```csharp
[Mapper]
public static partial class ModelMapper
{
public static partial FruitDto MapFruit(Fruit source)
{
return source switch
{
Banana x => MapToBananaDto(x),
Apple x => MapToAppleDto(x),
_ => throw new System.ArgumentException($"Cannot map {source.GetType()} to FruitDto as there is no known derived type mapping", nameof(source)),
};
}

// ... implementations of MapToBananaDto and MapToAppleDto
}
```

</TabItem>
<TabItem value="declaration" label="Declaration" default>
```csharp
[Mapper]
public static partial class ModelMapper
{
// highlight-start
[MapDerivedType<Banana, BananaDto>] // for c# language level ≥ 11
[MapDerivedType(typeof(Apple), typeof(AppleDto))] // for c# language level < 11
// highlight-end
public static partial FruitDto MapFruit(Fruit source);
}
abstract class Fruit {}
class Banana : Fruit {}
class Apple : Fruit {}
abstract class FruitDto {}
class BananaDto : FruitDto {}
class AppleDto : FruitDto {}
```
</TabItem>
<TabItem value="generated" label="Generated code" default>
```csharp
[Mapper]
public static partial class ModelMapper
{
public static partial FruitDto MapFruit(Fruit source)
{
return source switch
{
Banana x => MapToBananaDto(x),
Apple x => MapToAppleDto(x),
_ => throw new System.ArgumentException($"Cannot map {source.GetType()} to FruitDto as there is no known derived type mapping", nameof(source)),
};
}
// ... implementations of MapToBananaDto and MapToAppleDto
}
```
</TabItem>
</Tabs>

All source types provided to the `MapDerivedTypeAttribute`
Expand Down
66 changes: 32 additions & 34 deletions docs/docs/configuration/enum.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,39 @@ Available strategies:

The `IgnoreCase` property allows to opt in for case insensitive mappings (defaults to `false`).

<!-- do not indent this, it won't work, https://stackoverflow.com/a/67579641/3302887 -->

<Tabs>
<TabItem value="global" label="Global (mapper level)" default>

Applied to all enums mapped inside this mapper.

```csharp
// highlight-start
[Mapper(EnumMappingStrategy = EnumMappingStrategy.ByName, EnumMappingIgnoreCase = true)]
// highlight-end
public partial class CarMapper
{
...
}
```

</TabItem>
<TabItem value="enum" label="Enum (mapping method level)">

Applied to the specific enum mapped by this method.
Attribute is only valid on mapping method with enums as parameters.

```csharp
[Mapper]
public partial class CarMapper
{
// highlight-start
[MapEnum(EnumMappingStrategy.ByName, IgnoreCase = true)]
// highlight-end
public partial CarMakeDto MapMake(CarMake make);
}
```

</TabItem>
<TabItem value="global" label="Global (mapper level)" default>
Applied to all enums mapped inside this mapper.
```csharp
// highlight-start
[Mapper(EnumMappingStrategy = EnumMappingStrategy.ByName, EnumMappingIgnoreCase = true)]
// highlight-end
public partial class CarMapper
{
...
}
```
</TabItem>
<TabItem value="enum" label="Enum (mapping method level)">
Applied to the specific enum mapped by this method.
Attribute is only valid on mapping method with enums as parameters.
```csharp
[Mapper]
public partial class CarMapper
{
// highlight-start
[MapEnum(EnumMappingStrategy.ByName, IgnoreCase = true)]
// highlight-end
public partial CarMakeDto MapMake(CarMake make);
}
```
</TabItem>
</Tabs>

## Manually mapped enum values
Expand Down
132 changes: 65 additions & 67 deletions docs/docs/configuration/mapper.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -74,40 +74,40 @@ or by setting the `IgnoreObsoleteMembersStrategy` option of the `MapperAttribute
| Target | Ignores target members with the `Obsolete` attribute |

<Tabs>
<TabItem value="global" label="Global (mapper level)" default>

Sets the `IgnoreObsoleteMembersStrategy` for all methods within the mapper,
by default it is `None` allowing obsolete source and target members to be mapped.
This can be overriden by individual mapping methods using `MapperIgnoreObsoleteMembersAttribute`.

```csharp
// highlight-start
[Mapper(IgnoreObsoleteMembersStrategy = IgnoreObsoleteMembersStrategy.Both)]
// highlight-end
public partial class CarMapper
{
...
}
```

</TabItem>
<TabItem value="method" label="Local (mapping method level)">

Method will use the provided ignore obsolete mapping strategy,
otherwise the `MapperAttribute` property `IgnoreObsoleteMembersStrategy` will be used.

```csharp
[Mapper]
public partial class CarMapper
{
// highlight-start
[MapperIgnoreObsoleteMembers(IgnoreObsoleteMembersStrategy.Both)]
// highlight-end
public partial CarMakeDto MapMake(CarMake make);
}
```

</TabItem>
<TabItem value="global" label="Global (mapper level)" default>
Sets the `IgnoreObsoleteMembersStrategy` for all methods within the mapper,
by default it is `None` allowing obsolete source and target members to be mapped.
This can be overriden by individual mapping methods using `MapperIgnoreObsoleteMembersAttribute`.
```csharp
// highlight-start
[Mapper(IgnoreObsoleteMembersStrategy = IgnoreObsoleteMembersStrategy.Both)]
// highlight-end
public partial class CarMapper
{
...
}
```
</TabItem>
<TabItem value="method" label="Local (mapping method level)">
Method will use the provided ignore obsolete mapping strategy,
otherwise the `MapperAttribute` property `IgnoreObsoleteMembersStrategy` will be used.
```csharp
[Mapper]
public partial class CarMapper
{
// highlight-start
[MapperIgnoreObsoleteMembers(IgnoreObsoleteMembersStrategy.Both)]
// highlight-end
public partial CarMakeDto MapMake(CarMake make);
}
```
</TabItem>
</Tabs>

### Property name mapping strategy
Expand Down Expand Up @@ -187,42 +187,40 @@ dotnet_diagnostic.RMG020.severity = error # Unmapped source member
To enforce strict mappings on only either the source or the target,
the `RequiredMappingStrategy` can be used.

<!-- do not indent this, it won't work, https://stackoverflow.com/a/67579641/3302887 -->

<Tabs>
<TabItem value="global" label="Global (mapper level)" default>

Sets the `RequiredMappingStrategy` for all methods within the mapper,
by default it is `Both` requiring all members to be mapped.
This can be overriden by individual mapping methods using `MapperRequiredMappingAttribute`.

```csharp
// highlight-start
[Mapper(RequiredMappingStrategy = RequiredMappingStrategy.Source)]
// highlight-end
public partial class CarMapper
{
...
}
```

</TabItem>
<TabItem value="enum" label="Enum (mapping method level)">

Applied to the specific mapping method.

```csharp
[Mapper]
public partial class CarMapper
{
<TabItem value="global" label="Global (mapper level)" default>

Sets the `RequiredMappingStrategy` for all methods within the mapper,
by default it is `Both` requiring all members to be mapped.
This can be overriden by individual mapping methods using `MapperRequiredMappingAttribute`.

```csharp
// highlight-start
[MapperRequiredMapping(RequiredMappingStrategy.Source)]
[Mapper(RequiredMappingStrategy = RequiredMappingStrategy.Source)]
// highlight-end
public partial CarDto MapMake(Car make);
}
```

</TabItem>
public partial class CarMapper
{
...
}
```

</TabItem>
<TabItem value="local" label="Local (mapping method level)">

Applied to the specific mapping method.

```csharp
[Mapper]
public partial class CarMapper
{
// highlight-start
[MapperRequiredMapping(RequiredMappingStrategy.Source)]
// highlight-end
public partial CarDto MapMake(Car make);
}
```

</TabItem>
</Tabs>

### Strict enum mappings
Expand Down
53 changes: 26 additions & 27 deletions docs/docs/configuration/queryable-projections.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,38 @@ description: Use queryable projections to map queryable objects and optimize ORM
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# IQueryable projections

Mapperly does support `IQueryable<T>` projections:

<!-- do not indent this, it won't work, https://stackoverflow.com/a/67579641/3302887 -->

<Tabs>
<TabItem value="definition" label="Mapper definition">

```csharp
[Mapper]
public static partial class CarMapper
{
// highlight-start
public static partial IQueryable<CarDto> ProjectToDto(this IQueryable<Car> q);
// highlight-end
}
```

</TabItem>
<TabItem value="usage" label="Usage">

```csharp
var dtos = await DbContext.Cars
.Where(...)
// highlight-start
.ProjectToDto()
// highlight-end
.ToListAsync();
```

</TabItem>
<TabItem value="definition" label="Mapper definition">
```csharp
[Mapper]
public static partial class CarMapper
{
// highlight-start
public static partial IQueryable<CarDto> ProjectToDto(this IQueryable<Car> q);
// highlight-end
}
```
</TabItem>
<TabItem value="usage" label="Usage">
```csharp
var dtos = await DbContext.Cars
.Where(...)
// highlight-start
.ProjectToDto()
// highlight-end
.ToListAsync();
```
</TabItem>
</Tabs>

This is useful in combination with Entity Framework and other ORM solutions which expose `IQueryable<T>`.
Expand Down
Loading

0 comments on commit 1ca20b1

Please sign in to comment.