Skip to content

Expose DefaultNameTranslator on INpgsqlTypeMapper#2137

Merged
austindrenski merged 2 commits intonpgsql:devfrom
austindrenski:expose-default-name-translator
Sep 1, 2018
Merged

Expose DefaultNameTranslator on INpgsqlTypeMapper#2137
austindrenski merged 2 commits intonpgsql:devfrom
austindrenski:expose-default-name-translator

Conversation

@austindrenski
Copy link
Contributor

@austindrenski austindrenski added this to the 4.1 milestone Aug 30, 2018
@austindrenski austindrenski self-assigned this Aug 30, 2018
@austindrenski austindrenski force-pushed the expose-default-name-translator branch from 4e77a3c to fa1a3e6 Compare August 30, 2018 02:49
@austindrenski austindrenski force-pushed the expose-default-name-translator branch from fa1a3e6 to ef9132a Compare August 30, 2018 02:54
[NotNull]
INpgsqlTypeMapper MapEnum<TEnum>(
[CanBeNull] string pgName = null,
[CanBeNull] INpgsqlNameTranslator nameTranslator = null)
Copy link
Contributor

@YohDeadfall YohDeadfall Aug 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't ReSharper understand nullability by default values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm mistaken, including these annotations here flows them onto implementation classes, which makes it simpler to ensure that concrete implementations all share the same semantics.

It should be obvious to anyone looking at the interface that these can be null, but since it's a public interface, I think it makes sense to add them.

As an example, imagine that an implementation has a different default value for pgName, like pgName = "test_name". With these annotations, ReSharper should still flow nullability info to the caller. But without these annotations, the nullability defaults to unknown (at least historically).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For god's sake I hope C# 8 comes out soon with nullable references...

Copy link
Contributor

@YohDeadfall YohDeadfall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but please address my comment before merging it.

@austindrenski
Copy link
Contributor Author

@roji This is blocking npgsql/efcore.pg#605 and npgsql/efcore.pg#621 where type mappings need a global fallback translator.

Could you take a quick look?

@roji
Copy link
Member

roji commented Aug 31, 2018

Promise to review this weekend... Sorry, the non-Npgsql workload is really intensive at the moment...

internal Dictionary<string, NpgsqlTypeMapping> Mappings { get; set; }

public INpgsqlNameTranslator DefaultNameTranslator { get; set; }
public abstract INpgsqlNameTranslator DefaultNameTranslator { get; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be missing something, but why not keep this a regular, non-virtual property on TypeMapperBase and make the setter protected? This would save having have two overrides of this property in GlobalTypeMapper and ConnectorTypeMapper...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's a silly oversight. Though, instead of a protected setter, it seems safer to pass this down to a base constructor.

@roji
Copy link
Member

roji commented Sep 1, 2018

Even better!

@austindrenski austindrenski merged commit 2c43e15 into npgsql:dev Sep 1, 2018
@austindrenski austindrenski deleted the expose-default-name-translator branch September 1, 2018 19:33
@austindrenski
Copy link
Contributor Author

@roji Since this doesn't seem to warrant being backported to 4.0.3, can we bump the dependency in EF Core provider to the unstable 4.1 build?

Its currently pointed at the unstable 4.0.3, but I imagine we plan to release 4.1 alongside 2.2?

@roji
Copy link
Member

roji commented Sep 1, 2018

@austindrenski I actually don't think we'll be releasing 4.1 alongside 2.2... 2.2 isn't too far off now (preview1 has already been released), whereas we haven't really done much for 4.1.

It makes more sense to me to backport this relatively risk-free change to 4.0.3 and take a dependency on that CI version...

@austindrenski
Copy link
Contributor Author

@roji In that case I'll backport and retarget those two PRs.

austindrenski added a commit to austindrenski/npgsql that referenced this pull request Sep 1, 2018
austindrenski added a commit that referenced this pull request Sep 1, 2018
roji pushed a commit that referenced this pull request Sep 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants