Skip to content

Commit

Permalink
Remove section on TValue customization
Browse files Browse the repository at this point in the history
This is for now an advanced corner use case.
  • Loading branch information
kzu committed Dec 21, 2024
1 parent 58ea63f commit 8bfbf9d
Showing 1 changed file with 0 additions and 33 deletions.
33 changes: 0 additions & 33 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,39 +233,6 @@ Things to note at template expansion time:
by anoother generator.


You can also customize code generation for the `TValue`s used in your struct ids.
For example, the support for automatically registering a generic `Dapper.SqlMapper.TypeHandler<T>`
when a `TValue` implements both `IParsable<T>` and `IFormattable` is implemented as a
so-called `TValue` template:

```csharp
[TValue]
file class TValue_TypeHandler : Dapper.SqlMapper.TypeHandler<TValue>
{
public override TValue Parse(object value) => TValue.Parse((string)value, null);

public override void SetValue(IDbDataParameter parameter, TValue value)
{
parameter.DbType = DbType.String;
parameter.Value = value.ToString(null, null);
}
}

file partial struct TValue : IParsable<TValue>, IFormattable
{
public static TValue Parse(string s, IFormatProvider? provider) => throw new NotImplementedException();
public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, [MaybeNullWhen(false)] out TValue result) => throw new NotImplementedException();
public string ToString(string? format, IFormatProvider? formatProvider) => throw new NotImplementedException();
}
```

If you use use [Ulid](https://github.com/Cysharp/Ulid) as a value type in your struct ids,
for example, the template will be applied since `Ulid` implements both `IParsable<T>` and
`IFormattable`. The generated code will look like this:

```csharp


<!-- #content -->
<!-- #ci -->

Expand Down

0 comments on commit 8bfbf9d

Please sign in to comment.