-
-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Non-trivial instance construction with factory methods #59
Non-trivial instance construction with factory methods #59
Conversation
# Conflicts: # src/Dapper.AOT.Analyzers/AnalyzerReleases.Unshipped.md # src/Dapper.AOT.Analyzers/CodeAnalysis/DapperInterceptorGenerator.cs # src/Dapper.AOT.Analyzers/CodeAnalysis/Diagnostics.cs # src/Dapper.AOT.Analyzers/Internal/Inspection.cs # src/Dapper.AOT.Analyzers/Internal/Roslyn/TypeSymbolExtensions.cs # test/Dapper.AOT.Test/Interceptors/GlobalFetchSize.output.netfx.cs # test/Dapper.AOT.Test/Interceptors/GlobalFetchSize.output.netfx.txt # test/Dapper.AOT.Test/Interceptors/QueryCustomConstructionWithConstructor.output.cs # test/Dapper.AOT.Test/Interceptors/QueryCustomConstructionWithConstructor.output.txt
Can we get a summary in the PR post about what the rules are? When it applies, what error conditions exist, etc. If there are error conditions that result in diagnostics: check out the "verifiers" folder - we now have extensive unit tests for all diagnostic outputs and see the /docs folder which has explanatory notes about every diagnostic, usually with examples of good/bad usage. |
I haven't looked at the code (hard to until I can see the rules considered :p), but also note: I've moved all but the most essential code to an analyzer now. If the interceptor path can short-cut any additional work needed to check all conditions, that's fine - the analyzer can do the extra work at lower priority. |
Additional additional thought: I wonder if it would be clearer to extend |
Hey @mgravell , I added PR description: please, let me know what you think about assumptions I am making.
I would propose renaming to |
@DeagleGross the attribute is ancient - I can't rename it. Options:
Note that I did switch the other constructor stuff to use this old attribute rather than DapperAotAttribute. Personally I'm not too concerned about the name being slightly weird - that might still be a better option that having more types. |
Hey @mgravell, I have done the following:
If that is fine, we need to release Dapper, update reference to latest in Dapper.AOT, test and merge current PR. |
@mgravell PR is ready, but we need to update the Dapper reference to make |
Idea:
Currently Dapper.AOT supports instance initialization via constructor using such syntax:
Idea is to support initialization of instances via factory methods:
Details:
1: Only such methods can be considered as
factory
methods for typeFoo
:Foo
(so the same as the containing type)2: To explicitly show intention to instantiate via the constructor, developer needs to mark constructor of type with ExplicitConstructorAttribute. To not complicate the attribute model, the same mechanism using the same attribute is used for factory methods instantiation.
3: Implementation is not starting to consider invisible (i.e. private) element members, if factory method is chosen to be used. Most of times immutable types with inaccessible members define a factory method (as in example below). To not complicate the flow depending on which construction mechanism is used, PR implementation does not consider hidden members in any of cases.
4: To not complicate the attribute model, PR implementation prioritizes constructor usage over factory method usage. So in example below instance initialization would be generated using constructor, not factory method. This is also covered by a separate diagnostic
DAP041: Constructor overrides factory method
:Flow change rules:
0) If type does not have factory method, then current behaviour should not be broken \ changed.
DAP041: Constructor overrides factory method
diagnostic is reported (warning level)ExplicitConstructor
attribute:ExplicitConstructor
attribute, then diagnosticDAP039: Multiple explicit factory methods
is reported.ExplicitConstructor
attribute) will be used. If multiple implicit factory methods found, then diagnosticDAP040: Ambiguous factory methods
is reported.Closes #34