Skip to content

Commit

Permalink
Updated readme. Added Writerside docs under /docs/site
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveDunn committed Oct 24, 2023
1 parent ba9fe32 commit 9fb37ba
Show file tree
Hide file tree
Showing 26 changed files with 1,133 additions and 3 deletions.
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ By default, each VO is decorated with a `TypeConverter` and `System.Text.Json` (
* Dapper
* EFCore
* [LINQ to DB](https://github.com/linq2db/linq2db)
* protobuf-net (see the FAQ section below)

They are controlled by the `Conversions` enum. The following has serializers for NSJ and STJ:

Expand Down Expand Up @@ -547,7 +548,7 @@ public partial struct CustomerId {

You *could*, but you'd get compiler warning [CS0282-There is no defined ordering between fields in multiple declarations of partial class or struct 'type'](https://docs.microsoft.com/en-us/dotnet/csharp/misc/cs0282)

### Why are there no implicit conversions to and from the primitive types that are being wrapped?
### Why are there, by default, no implicit conversions to and from the primitive types that are being wrapped?

Implicit operators can be useful, but for Value Objects, they can confuse things. Take the following code **without** any implicit conversions:

Expand Down Expand Up @@ -577,9 +578,11 @@ But since users of Vogen can declare a Value Object as a `class` **or** `struct`

### Can you opt-in to implicit conversions?

No, but you can provide them yourself. For certain types it would allow a much more natural way of expressing, er, expressions.
Yes, by specifying the `toPrimitiveCasting` and `fromPrimitiveCasting` in either local or global config.
By default, explicit operators are generated for both. Bear in mind that you can only define implicit _or_ explicit operators;
you can't have both.

Although it can be confusing. Let's say there's a type like this (and imagine that there's implicit conversions to `Age` and to `int`'):
Also, bear in mind that ease of use can cause confusions. Let's say there's a type like this (and imagine that there's implicit conversions to `Age` and to `int`'):

```csharp
[ValueObject(typeof(int))]
Expand Down Expand Up @@ -793,6 +796,23 @@ Linq2DB 4.0 or greater supports `DateOnly` and `TimeOnly`. Vogen generates value

`MappingSchema.Default.SetConverter<DateTime, TimeOnly>(dt => TimeOnly.FromDateTime(dt));`

### Can I use protobuf-net?

Yes. Add a dependency to protobuf-net and set a surrogate attribute:

```csharp
[ValueObject(typeof(string))]
[ProtoContract(Surrogate = typeof(string))]
public partial class BoxId {
//...
}
```

BoxId type now will be serialized as a string in all messages/grpc calls. If one is generating .proto files for other
applications from C# code, proto files will include Surrogate type as the type.
_thank you to [@DomasM](https://github.com/DomasM) for this information_.


## Attribution

I took a lot of inspiration from [Andrew Lock's](https://github.com/andrewlock) [StronglyTypedId](https://github.com/andrewlock/StronglyTypedId).
Expand Down
31 changes: 31 additions & 0 deletions docs/site/Writerside/adoc.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE instance-profile
SYSTEM "https://resources.jetbrains.com/writerside/1.0/product-profile.dtd">

<instance-profile id="adoc"
name="API Docs"
start-page="api-docs.md">

<toc-element topic="api-docs.md"/>
<toc-element topic="API-quickstart.md"/>
<toc-element topic="API-reference.md">
<toc-element topic="Pet.md">
</toc-element>
<toc-element toc-title="Store">
<toc-element topic="Returns-pet-inventories-by-status.md"/>
<toc-element topic="Place-an-order-for-a-pet.md"/>
<toc-element topic="Find-purchase-order-by-ID.md"/>
<toc-element topic="Delete-purchase-order-by-ID.md"/>
</toc-element>
<toc-element toc-title="User">
<toc-element topic="Create-user.md"/>
<toc-element topic="Creates-list-of-users-with-given-input-array.md"/>
<toc-element topic="Logs-user-into-the-system.md"/>
<toc-element topic="Logs-out-current-logged-in-user-session.md"/>
<toc-element topic="Get-user-by-user-name.md"/>
<toc-element topic="Update-user.md"/>
<toc-element topic="Delete-user.md"/>
</toc-element>
</toc-element>
<toc-element topic="Changes.md"/>
</instance-profile>
6 changes: 6 additions & 0 deletions docs/site/Writerside/c.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE categories
SYSTEM "https://resources.jetbrains.com/writerside/1.0/categories.dtd">
<categories>
<category id="wrs" name="Writerside documentation" order="1"/>
</categories>
Loading

0 comments on commit 9fb37ba

Please sign in to comment.