Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveDunn committed Jul 28, 2024
1 parent 190f931 commit 7c342a5
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@ How to create and use Value Objects, how they better represent domain concepts,
that no invalid instances can be created.
</card-summary>

<note>
This topic is incomplete and is currently being improved.
</note>

Create a new Value Object by decorating a partial type with the `ValueObject` attribute:
Create a new value object by decorating a partial type with the `ValueObject` attribute:

```c#
[ValueObject<int>]
public partial struct CustomerId { }
```

The type must be `partial` as the source generator augments the type with another partial class containing the
generator code.
generated code.

Now, create a new instance by using the `From` method:

Expand All @@ -36,4 +32,10 @@ public void HandlePayment(
PaymentAmount paymentAmount)
```

[//]: # (TODO: enhance)
If your type has [validation](Validate-values.md), then the `From` method will throw an exception if validation fails.

This stops invalid instances being created, but exceptions might not be desirable.
In this case, use the `TryFrom` method.
There are two overloads for this.
One returns a `ValueObjectOrError<T>` and one returns a bool and takes an `out` parameter.

0 comments on commit 7c342a5

Please sign in to comment.