Skip to content
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

Support hierarchical record creation from generated dynamic factory #47

Closed
kzu opened this issue Nov 9, 2022 · 0 comments · Fixed by #48
Closed

Support hierarchical record creation from generated dynamic factory #47

kzu opened this issue Nov 9, 2022 · 0 comments · Fixed by #48
Labels
enhancement New feature or request

Comments

@kzu
Copy link
Member

kzu commented Nov 9, 2022

Currently, say we have a couple records like:

public partial record Point(int X, int Y);

public partial record Line(Point Start, Point End);

public record OnDidDrawLine(Line Line);

When an event of type OnDidDrawLine coming from different assemblies is published,
currently the subscriber will fail because the generated factory for it will essentially be
doing new OnDidDrawLine(value.Line), and attempting to pass the Line type from the
wrong assembly to that constructor.

What we need is a generator that will instead generate new OnDidDrawLine(Line.Create(value.Line))
where the Line factory method would in turn invoke the Point factory and so on. This
would allow supporting entire object hierarchies purely from generated factories.

Note that this does not involve the automatic creation of list-based properties, since
that would be a nice to have for another issue, perhaps.

kzu added a commit that referenced this issue Nov 9, 2022
We now invoke factories automatically whenever they are
found.

A new diagnostic is reported if a `Create(dynamic value)` factory
method is found in the record but it's not accessible to the
generated factory in the current assembly. The diagnostic is
nevertheless a warning since in that case we still generate our
custom factory, but users will not get the benefit of invoking
their custom factory (although this might be by design if it's
just a coincidence in the method name and signature they
chose for an entirely unrelated purpose).

Closes #47
kzu added a commit that referenced this issue Nov 9, 2022
We now invoke factories automatically whenever they are
found.

A new diagnostic is reported if a `Create(dynamic value)` factory
method is found in the record but it's not accessible to the
generated factory in the current assembly. The diagnostic is
nevertheless a warning since in that case we still generate our
custom factory, but users will not get the benefit of invoking
their custom factory (although this might be by design if it's
just a coincidence in the method name and signature they
chose for an entirely unrelated purpose).

Closes #47
kzu added a commit that referenced this issue Nov 9, 2022
We now invoke factories automatically whenever they are
found.

A new diagnostic is reported if a `Create(dynamic value)` factory
method is found in the record but it's not accessible to the
generated factory in the current assembly. The diagnostic is
nevertheless a warning since in that case we still generate our
custom factory, but users will not get the benefit of invoking
their custom factory (although this might be by design if it's
just a coincidence in the method name and signature they
chose for an entirely unrelated purpose).

Closes #47
@kzu kzu added the enhancement New feature or request label Nov 9, 2022
kzu added a commit that referenced this issue Nov 9, 2022
We now invoke factories automatically whenever they are
found.

A new diagnostic is reported if a `Create(dynamic value)` factory
method is found in the record but it's not accessible to the
generated factory in the current assembly. The diagnostic is
nevertheless a warning since in that case we still generate our
custom factory, but users will not get the benefit of invoking
their custom factory (although this might be by design if it's
just a coincidence in the method name and signature they
chose for an entirely unrelated purpose).

Closes #47
@kzu kzu closed this as completed in #48 Nov 10, 2022
kzu added a commit that referenced this issue Nov 10, 2022
We now invoke factories automatically whenever they are
found.

A new diagnostic is reported if a `Create(dynamic value)` factory
method is found in the record but it's not accessible to the
generated factory in the current assembly. The diagnostic is
nevertheless a warning since in that case we still generate our
custom factory, but users will not get the benefit of invoking
their custom factory (although this might be by design if it's
just a coincidence in the method name and signature they
chose for an entirely unrelated purpose).

Closes #47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant