Repository navigation
Add support to parse IP and MAC addresses - #535
Conversation
- `IPAddress.Parse(string)` - `PhysicalAddres.Parse(string)`
| public Expression Translate(MethodCallExpression expression) | ||
| { | ||
| if (expression.Method.DeclaringType != typeof(NpgsqlNetworkExtensions)) | ||
| var declaringType = expression.Method.DeclaringType; |
There was a problem hiding this comment.
I'd prefer it if we handled the IPAddress and PhysicalAddress methods separately, rather than include them in the big switch below. As it is, in theory, if a method called LessThan (or any other method below) existed on IPAddress or PhysicalAddress, it would get mistakenly translated. So I'd first take care of the Parse() cases, and then move ahead as before to the switch over all NpgsqlNetworkExtensions methods.
I do admit this is probably a bit of theoretical OCD on my side :)
There was a problem hiding this comment.
I like that idea. I'd prefer to still use one translator class though, but with the Parse(string) handling separated from the main switch.
There was a problem hiding this comment.
Absolutely, no need for multiple translators.
| public NpgsqlEvaluatableExpressionFilter([NotNull] IModel model) : base(model) {} | ||
|
|
||
| /// <inheritdoc /> | ||
| public override bool IsEvaluatableMethodCall(MethodCallExpression methodCallExpression) |
There was a problem hiding this comment.
As explained in #534 (comment), we shouldn't be touching NpgsqlEvaluatableExpressionFilter at all.
| switch (expression.Method.Name) | ||
| { | ||
| case nameof(IPAddress.Parse) when declaringType == typeof(IPAddress): | ||
| return new ExplicitCastExpression(expression.Arguments[0], typeof(IPAddress)); |
There was a problem hiding this comment.
Continuing the OCD mood from above, if the expression is a constant we may want to use the literal PostgreSQL syntax: IPADDR '127.0.0.1' rater than the cast syntax CAST('127.0.0.1' AS IPADDR). The former is cleaner SQL and clearly indicates the constant-ness in the expression (and therefore cannot also be parameterized). You can use SqlFragmentExpression to easily generate it.
However, this is really a nit and we don't have to do it.
There was a problem hiding this comment.
We don't actually have a chance to do this, per #534 (comment). Though, I like the idea about SqlFragmentExpression.
|
|
||
| /// <inheritdoc /> | ||
| protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | ||
| => base.OnConfiguring(optionsBuilder.EnableSensitiveDataLogging()); |
There was a problem hiding this comment.
Out of curiosity, what is the need for this? You don't seem to actually be looking at parameter data in these tests...
There was a problem hiding this comment.
As part of the panic, I was looking at the values being assigned to the parameters. Reverting this in the next commit.
roji
left a comment
There was a problem hiding this comment.
Looks good! See my tiny nit and merge at will... Thanks!
| public Expression Translate(MethodCallExpression expression) | ||
| { | ||
| if (expression.Method.DeclaringType != typeof(NpgsqlNetworkExtensions)) | ||
| MethodInfo method = expression.Method; |
07a3f3d to
f4aaec8
Compare
IPAddress.Parse(string)PhysicalAddres.Parse(string)Related
#534