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

Simplify reflection of classes generated by annotations framework #1760

Open
2 tasks
Kralizek opened this issue Jun 14, 2024 · 6 comments
Open
2 tasks

Simplify reflection of classes generated by annotations framework #1760

Kralizek opened this issue Jun 14, 2024 · 6 comments
Labels
annotations feature-request A feature should be added or improved. p2 This is a standard priority issue

Comments

@Kralizek
Copy link

Describe the feature

I'm using reflection to find the class generated by the annotation framework.

Whilst the approach is easily reproducible because the class name is "{Class}_{Method}_Generated" and the method is Method, it would be easier if the generated class was decorated with a attribute (possibly one coming from the BCL) that can be used to quickly find the generated class given the original class/function.

Additionally, it would be great if the generated class had the method with a fixed name like Handle or whatever.

Using a marking attribute and maybe even some interface with a single Handle method would make the process easier and less relying on internal implementation.

Use Case

I'm working on a tool to improve development experience when working with Annotations Lambda

Proposed Solution

No response

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

AWS .NET SDK and/or Package version used

Any

Targeted .NET Platform

.NET 8 + Aspire

Operating System and version

Any

@Kralizek Kralizek added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jun 14, 2024
@bhoradc bhoradc added needs-review annotations p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. needs-review labels Jun 14, 2024
@normj
Copy link
Member

normj commented Jun 14, 2024

What attribute do you suggest putting on the generated handler? I don't want something that users could get confused an attempt to use themselves in their code. If we can agree on attribute I don't see any reason we couldn't add the feature, would you be interested in contributing a PR?

@Kralizek
Copy link
Author

I didn't do any research regarding the best attribute type.

I remember both EF and WCF decorating their generated code with GeneratedCodeAttribute but this attribute takes a tool name and version. I don't remember on top of my mind if you use it already, but it would be semantically incorrect anyway.

Another option would be to use something from the ComponentModel namespace but they seem to carry some special meaning for the runtime, so I'm highly skeptical about using any of these.

The only option seems to be the creation of a ad-hoc attribute and then use reflection to extract its values without having the attribute type definition available (although I'm not sure about whether a type defined in the Annotation assembly is not available down the line).

Regarding working on the pull request, I would need some guidance or at least some docs to understand the code generation process. I saw there are both cs and tt files that seem somehow related to the issue.

PS: I would assume changing the name of the generated method to a fixed value is too big of a breaking change?

@Kralizek
Copy link
Author

@normj I got some time to look at this. Do you have the time to finalize the discussion bullets above?

@normj
Copy link
Member

normj commented Sep 13, 2024

I like idea of using GeneratedCodeAttribute with a tool name of the package name Amazon.Lambda.Annotations. There is also already logic that is accessible in the tt files to get ahold of the version as well. https://github.com/aws/aws-lambda-dotnet/blob/master/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/LambdaFunctionTemplate.tt#L84

We have also had some discussion of reworking the generator function name because the generated name can exceed the limit that can fit in the Function Handler property. So it would be good to have add this to move away from assuming the function's generated name.

@Kralizek
Copy link
Author

Kralizek commented Sep 13, 2024

Would you consider changing the name of the generated method a breaking change worth of a major semver hop?

@normj
Copy link
Member

normj commented Sep 13, 2024

Possibly, we haven't figured out the approach how we want to handle the issue. One approach is still generate the current format and a new format so anybody reference the current format would still work. If we do it that way then I think we would move the GenerateCodeAttribute to the new method. To be clear we would generate the current formatted version and then have it call the new format so there would be little extra code generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
annotations feature-request A feature should be added or improved. p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

3 participants