Skip to content

Commit

Permalink
Set hint size for IPAddress string representation to 45
Browse files Browse the repository at this point in the history
Part of #18662
  • Loading branch information
roji committed Jun 6, 2020
1 parent 9f316e5 commit 1fc11f8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/EFCore/Storage/ValueConversion/IPAddressToStringConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ namespace Microsoft.EntityFrameworkCore.Storage.ValueConversion
/// </summary>
public class IPAddressToStringConverter : ValueConverter<IPAddress, string>
{
// IPv4-mapped IPv6 addresses can go up to 45 bytes, e.g. 0000:0000:0000:0000:0000:ffff:192.168.1.1
private static readonly ConverterMappingHints _defaultHints
= new ConverterMappingHints(size: 45);

/// <summary>
/// Creates a new instance of this converter.
/// </summary>
Expand All @@ -24,15 +28,18 @@ public IPAddressToStringConverter([CanBeNull] ConverterMappingHints mappingHints
: base(
ToString(),
ToIPAddress(),
mappingHints)
_defaultHints.With(mappingHints))
{
}

/// <summary>
/// A <see cref="ValueConverterInfo" /> for the default use of this converter.
/// </summary>
public static ValueConverterInfo DefaultInfo { get; }
= new ValueConverterInfo(typeof(IPAddress), typeof(string), i => new IPAddressToStringConverter(i.MappingHints));
= new ValueConverterInfo(
typeof(IPAddress),
typeof(string), i => new IPAddressToStringConverter(i.MappingHints),
_defaultHints);

private static new Expression<Func<IPAddress, string>> ToString()
=> v => v == null ? default : v.ToString();
Expand Down

0 comments on commit 1fc11f8

Please sign in to comment.