-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
TimeSpanToTicksConverter.cs
45 lines (41 loc) · 1.75 KB
/
TimeSpanToTicksConverter.cs
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
37
38
39
40
41
42
43
44
45
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace Microsoft.EntityFrameworkCore.Storage.ValueConversion;
/// <summary>
/// Converts <see cref="TimeSpan" /> to and <see cref="TimeSpan.Ticks" />.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-value-converters">EF Core value converters</see> for more information and examples.
/// </remarks>
public class TimeSpanToTicksConverter : ValueConverter<TimeSpan, long>
{
/// <summary>
/// Creates a new instance of this converter.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-value-converters">EF Core value converters</see> for more information and examples.
/// </remarks>
public TimeSpanToTicksConverter()
: this(null)
{
}
/// <summary>
/// Creates a new instance of this converter.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-value-converters">EF Core value converters</see> for more information and examples.
/// </remarks>
/// <param name="mappingHints">
/// Hints that can be used by the <see cref="ITypeMappingSource" /> to create data types with appropriate
/// facets for the converted data.
/// </param>
public TimeSpanToTicksConverter(ConverterMappingHints? mappingHints)
: base(v => v.Ticks, v => new TimeSpan(v), mappingHints)
{
}
/// <summary>
/// A <see cref="ValueConverterInfo" /> for the default use of this converter.
/// </summary>
public static ValueConverterInfo DefaultInfo { get; }
= new(typeof(TimeSpan), typeof(long), i => new TimeSpanToTicksConverter(i.MappingHints));
}