forked from npgsql/npgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypeHandler.snbtxt
More file actions
36 lines (31 loc) · 1.74 KB
/
TypeHandler.snbtxt
File metadata and controls
36 lines (31 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{{ for using in usings }}
using {{ using }};
{{ end }}
#nullable enable
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
#pragma warning disable RS0016 // Add public types and members to the declared API
#pragma warning disable 618 // Member is obsolete
namespace {{ namespace }}
{
partial class {{ type_name }}
{
public override int ValidateObjectAndGetLength(object value, ref NpgsqlLengthCache? lengthCache, NpgsqlParameter? parameter)
=> value switch
{
{{ for interface in interfaces }}
{{ interface.handled_type }} converted => (({{ interface.name }})this).ValidateAndGetLength(converted, {{ is_simple ? "" : "ref lengthCache, " }}parameter),
{{ end }}
_ => throw new InvalidCastException($"Can't write CLR type {value.GetType()} with handler type {{ type_name }}")
};
public override Task WriteObjectWithLength(object? value, NpgsqlWriteBuffer buf, NpgsqlLengthCache? lengthCache, NpgsqlParameter? parameter, bool async, CancellationToken cancellationToken = default)
=> value switch
{
{{ for interface in interfaces }}
{{ interface.handled_type }} converted => WriteWithLength(converted, buf, lengthCache, parameter, async, cancellationToken),
{{ end }}
DBNull => WriteWithLength(DBNull.Value, buf, lengthCache, parameter, async, cancellationToken),
null => WriteWithLength(DBNull.Value, buf, lengthCache, parameter, async, cancellationToken),
_ => throw new InvalidCastException($"Can't write CLR type {value.GetType()} with handler type {{ type_name }}")
};
}
}